#!/usr/bin/perl -w
-if (@ARGV != 3) {
- print STDERR "Syntax: ${0} host /path/to/file.rrd /output/directory/\n";
+if ((@ARGV != 3) && (@ARGV != 4)) {
+ print STDERR "Syntax: ${0} host /path/to/file.rrd /output/directory/ [uid]\n";
exit(1);
}
use Net::SNMP;
+if ($> == 0) {
+ if (@ARGV != 4) {
+ print STDERR "Running as root, please provide UID as 4th argument!\n";
+ exit(1);
+ }
+
+ print "Running as root, switching to ".$ARGV[3]."\n";
+ $< = $> = $ARGV[3];
+}
+
if (! -e "${rrdfile}") {
my $cmd = "rrdtool create \"${rrdfile}\" ";
foreach my $var (@fields) {