From af4abf85a0f06568e1bed0cd2e3b36363b0b37ed Mon Sep 17 00:00:00 2001 From: Michael Gernoth Date: Thu, 17 Dec 2009 16:34:21 +0100 Subject: [PATCH] change uid when invoked as root --- upsgraph.pl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/upsgraph.pl b/upsgraph.pl index aa77721..bef10a5 100755 --- a/upsgraph.pl +++ b/upsgraph.pl @@ -1,7 +1,7 @@ #!/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); } @@ -97,6 +97,16 @@ my $vars = { 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) { -- 2.39.2