#!/usr/bin/perl -w
use strict;
my $sudo_binary = "/usr/bin/sudo";
my $apt_get_binary = "/usr/bin/apt-get";
my $command = "$sudo_binary $apt_get_binary update";
my $output = `$command`;
$command = "$sudo_binary $apt_get_binary -s upgrade";
$output = `$command`;
my @lines = split(/\n/,$output);
foreach(@lines){
if($_ =~ /^([0-9]+)\s+upgraded/){
if($1 > 0){
print "CRITICAL - There are $1 updates available\n";
exit 2;
}
else{
print "OK - System up to date";
exit 0;
}
}
}
print "UNKNOWN - Unable to run apt-get update/upgrade";
exit 3;