diff options
author | Peter Palfrader <peter@palfrader.org> | 2008-05-20 21:36:21 +0000 |
---|---|---|
committer | weasel <weasel@bc3d92e2-beff-0310-a7cd-cc87d7ac0ede> | 2008-05-20 21:36:21 +0000 |
commit | b486e2ac126f0ccb3bccd4ba69ae8bfc436e6354 (patch) | |
tree | 95b4d61f6ab7bea7af1425d9d7f209ed27704a46 /nagios-check-apt-updates | |
parent | 09be493b7cf9e6fe8dee1aad6df97797c7e80db0 (diff) |
Add --noupdate
git-svn-id: svn+ssh://asteria.noreply.org/svn/weaselutils/trunk@351 bc3d92e2-beff-0310-a7cd-cc87d7ac0ede
Diffstat (limited to 'nagios-check-apt-updates')
-rwxr-xr-x | nagios-check-apt-updates | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/nagios-check-apt-updates b/nagios-check-apt-updates index 346a49d..b65e6a0 100755 --- a/nagios-check-apt-updates +++ b/nagios-check-apt-updates @@ -34,25 +34,27 @@ delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; my $APT = '/usr/bin/apt-get'; my $VERBOSE; -sub do_check($$$$$) { - my ($pre_command, $timeout, $name, $updates_security, $updates_other) = @_; +sub do_check($$$$$$) { + my ($pre_command, $timeout, $noupdate, $name, $updates_security, $updates_other) = @_; my $fh; my $pid; my @command; - print STDERR "Running $APT update in $name\n" if $VERBOSE; - @command = ($APT, 'update'); - unshift @command, @$pre_command; - $fh = new IO::Handle; - $pid = open2($fh, \*STDIN, @command) or die ("Cannot run $APT update in $name: $!\n"); - local $SIG{ALRM} = sub { die "Timeout for apt-get update.\n" }; - alarm $timeout; - my @ignore=<$fh>; - alarm 0; - close $fh; - waitpid $pid, 0; - if ($CHILD_ERROR) { # program failed - die("$APT update returned with non-zero exit code in $name: ".($CHILD_ERROR / 256)."\n"); + unless ($noupdate) { + print STDERR "Running $APT update in $name\n" if $VERBOSE; + @command = ($APT, 'update'); + unshift @command, @$pre_command; + $fh = new IO::Handle; + $pid = open2($fh, \*STDIN, @command) or die ("Cannot run $APT update in $name: $!\n"); + local $SIG{ALRM} = sub { die "Timeout for apt-get update.\n" }; + alarm $timeout; + my @ignore=<$fh>; + alarm 0; + close $fh; + waitpid $pid, 0; + if ($CHILD_ERROR) { # program failed + die("$APT update returned with non-zero exit code in $name: ".($CHILD_ERROR / 256)."\n"); + }; }; print STDERR "Running $APT --simulate upgrade in $name\n" if $VERBOSE; @@ -107,6 +109,7 @@ if (!GetOptions ( '--help' => \$params->{'help'}, '--version' => \$params->{'version'}, '--sudo' => \$params->{'sudo'}, + '--noupdate' => \$params->{'noupdate'}, '--nosudo' => \$params->{'nosudo'}, '--verbose' => \$params->{'verbose'}, '--warnifupdates' => \$params->{'warnifupdates'}, @@ -124,6 +127,7 @@ if ($params->{'help'}) { print " --help Print this short help.\n"; print " --version Report version number.\n"; print " --sudo Use sudo to call apt-get (default).\n"; + print " --noupdate Do not run apt-get update first.\n"; print " --nosudo Do not use sudo to call apt-get.\n"; print " --warnifupdates Exit with a WARNING status if any updates are available.\n"; print " --timeout=<timeout> Timeout in seconds for each of the two apt-get runs.\n"; @@ -186,7 +190,7 @@ for my $root (@chroots) { my @pre_command = (); unshift @pre_command, 'chroot', $root if ($root ne '/'); unshift @pre_command, 'sudo' if $use_sudo; - do_check(\@pre_command, $params->{'timeout'}, $root, \@updates_security, \@updates_other); + do_check(\@pre_command, $params->{'timeout'}, $params->{'noupdate'}, $root, \@updates_security, \@updates_other); } # Make sure vserver names are nice; @@ -202,7 +206,7 @@ for my $vserver (@vservers) { my @pre_command = (); unshift @pre_command, '/usr/sbin/vserver', $vserver, 'exec'; unshift @pre_command, 'sudo' if $use_sudo; - do_check(\@pre_command, $params->{'timeout'}, $vserver, \@updates_security, \@updates_other); + do_check(\@pre_command, $params->{'timeout'}, $params->{'noupdate'}, $vserver, \@updates_security, \@updates_other); } |