version 1.10, 2007/12/04 04:43:24
|
version 1.15, 2011/10/19 03:21:29
|
Line 1
|
Line 1
|
#!/usr/bin/perl -w |
#!/usr/bin/perl |
# |
# |
# The LearningOnline Network with CAPA |
# The LearningOnline Network with CAPA |
# Checks status of RPM packages on system. |
# Checks status of RPM packages on system. |
# |
# |
|
# $Id$ |
|
# |
# Copyright Michigan State University Board of Trustees |
# Copyright Michigan State University Board of Trustees |
# |
# |
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
# This file is part of the LearningOnline Network with CAPA (LON-CAPA). |
Line 30
|
Line 32
|
|
|
=head1 NAME |
=head1 NAME |
|
|
B<CHECKRPMS> - automated status report about RPMs on a system. |
B<CHECKRPMS> - automated status report about RPMs (RHEL/Fedora/CentOS/SuSE) |
|
or debs (Debian/Ubuntu) on a system. |
|
|
=head1 DESCRIPTION |
=head1 DESCRIPTION |
|
|
Line 39 to LON-CAPA systems. distprobe is used t
|
Line 42 to LON-CAPA systems. distprobe is used t
|
|
|
The utility which is used to complete the check depends on the distro: |
The utility which is used to complete the check depends on the distro: |
|
|
fedora, rhel 5/5+, centos, scientific - yum |
fedora, rhel >= 5, centos, scientific - yum |
suse 9.X and sles9 - you |
suse 9.X and sles9 - you |
suse 10.2,10.3 - zypper |
suse 10.2,10.3,11.1,11.2,11.3,11.4,sles11 - zypper |
sles10,suse10.1 - rug |
sles10,suse10.1 - rug |
rhel 4 - up2date |
rhel 4 - up2date |
|
debian, ubuntu - apt-get |
others - check-rpms |
others - check-rpms |
|
|
Created by amalgamating previous distribution-specific CHECKRPMS.dist files (where dist was one of: fedora, rhel, suse, sles10, default). |
Created by amalgamating previous distribution-specific CHECKRPMS.dist files (where dist was one of: fedora, rhel, suse, sles10, default). |
Line 59 use Apache::loncommon();
|
Line 63 use Apache::loncommon();
|
|
|
my $tmpfile = '/tmp/CHECKRPMS.'.$$; |
my $tmpfile = '/tmp/CHECKRPMS.'.$$; |
my $perlvar= LONCAPA::Configuration::read_conf('loncapa.conf'); |
my $perlvar= LONCAPA::Configuration::read_conf('loncapa.conf'); |
|
my $docroot = $perlvar->{'lonDocRoot'}; |
|
|
# Determine who we email |
# Determine who we email |
my $defdom = $perlvar->{'lonDefDomain'}; |
my $defdom = $perlvar->{'lonDefDomain'}; |
Line 80 open(TMPFILE,">$tmpfile");
|
Line 85 open(TMPFILE,">$tmpfile");
|
print TMPFILE localtime(time).' '.$hostname."\n"; |
print TMPFILE localtime(time).' '.$hostname."\n"; |
close(TMPFILE); |
close(TMPFILE); |
|
|
|
if ($docroot ne '') { |
|
if (-e "$docroot/lon-status/checkrpms.txt") { |
|
unlink("$docroot/lon-status/checkrpms.txt"); |
|
} |
|
} |
|
|
my ($cmd,$send,$addsubj); |
my ($cmd,$send,$addsubj); |
if ($distro =~ /^fedora\d+$/) { |
if ($distro =~ /^fedora\d+$/) { |
$cmd = 'yum update'; |
$cmd = 'yum update'; |
Line 89 if ($distro =~ /^fedora\d+$/) {
|
Line 100 if ($distro =~ /^fedora\d+$/) {
|
$cmd = 'you'; |
$cmd = 'you'; |
&prepare_msg($tmpfile,$cmd); |
&prepare_msg($tmpfile,$cmd); |
($send,$addsubj) = &check_with_you($tmpfile); |
($send,$addsubj) = &check_with_you($tmpfile); |
} elsif ($distro =~ /^suse10\.(\d)$/) { |
} elsif ($distro =~ /^suse(\d{2,})\.(\d+)$/) { |
my $version =$1; |
my $version =$1; |
if ($version > 1) { |
my $subversion = $2; |
|
if (($version > 10) || (($version == 10) && ($subversion > 1))) { |
$cmd = 'zypper up'; |
$cmd = 'zypper up'; |
&prepare_msg($tmpfile,$cmd); |
&prepare_msg($tmpfile,$cmd); |
($send,$addsubj) = &check_with_zypper($tmpfile); |
($send,$addsubj) = &check_with_zypper($tmpfile); |
Line 104 if ($distro =~ /^fedora\d+$/) {
|
Line 116 if ($distro =~ /^fedora\d+$/) {
|
$cmd = 'rug up'; |
$cmd = 'rug up'; |
&prepare_msg($tmpfile,$cmd); |
&prepare_msg($tmpfile,$cmd); |
($send,$addsubj) = &check_with_rug($tmpfile); |
($send,$addsubj) = &check_with_rug($tmpfile); |
|
} elsif ($distro =~ /^sles(\d+)$/) { |
|
$cmd = 'zypper up'; |
|
&prepare_msg($tmpfile,$cmd); |
|
($send,$addsubj) = &check_with_zypper($tmpfile); |
} elsif ($distro =~ /^rhes(\d+)$/) { |
} elsif ($distro =~ /^rhes(\d+)$/) { |
my $version = $1; |
my $version = $1; |
if ($version == 4) { |
if ($version == 4) { |
Line 119 if ($distro =~ /^fedora\d+$/) {
|
Line 135 if ($distro =~ /^fedora\d+$/) {
|
$cmd = 'yum update'; |
$cmd = 'yum update'; |
&prepare_msg($tmpfile,$cmd); |
&prepare_msg($tmpfile,$cmd); |
($send,$addsubj) = &check_with_yum($tmpfile); |
($send,$addsubj) = &check_with_yum($tmpfile); |
} elsif ($distro =~ /^scientific\d+\.\d$/) { |
} elsif ($distro =~ /^scientific\d+$/) { |
$cmd = 'yum update'; |
$cmd = 'yum update'; |
&prepare_msg($tmpfile,$cmd); |
&prepare_msg($tmpfile,$cmd); |
($send,$addsubj) = &check_with_yum($tmpfile); |
($send,$addsubj) = &check_with_yum($tmpfile); |
|
} elsif ($distro =~ /^(debian|ubuntu)\d+/) { |
|
$cmd = 'apt-get upgrade'; |
|
&prepare_msg($tmpfile,$cmd); |
|
($send,$addsubj) = &check_with_apt($tmpfile); |
} else { |
} else { |
$cmd = '/usr/local/bin/check-rpms --update'; |
$cmd = '/usr/local/bin/check-rpms --update'; |
($send,$addsubj) = &check_with_checkrpms($tmpfile); |
($send,$addsubj) = &check_with_checkrpms($tmpfile); |
} |
} |
if ($send) { |
if ($send) { |
$subj .= $addsubj; |
$subj .= $addsubj; |
|
if ($docroot ne '') { |
|
system("cat $tmpfile > $docroot/lon-status/checkrpms.txt"); |
|
if ($< == 0) { |
|
system("chown www:www $docroot/lon-status/checkrpms.txt"); |
|
} |
|
chmod(0600,$docroot/lon-status/checkrpms.txt"); |
|
} |
system(qq{mail -s '$subj' "$emailto" < $tmpfile}); |
system(qq{mail -s '$subj' "$emailto" < $tmpfile}); |
} |
} |
|
|
Line 354 sub check_with_zypper {
|
Line 381 sub check_with_zypper {
|
$sendflag = 1; |
$sendflag = 1; |
} |
} |
return ($sendflag,$append_to_subj); |
return ($sendflag,$append_to_subj); |
|
} |
|
|
|
sub check_with_apt { |
|
my ($tmpfile) = @_; |
|
my $apt = '/usr/bin/apt-get'; |
|
my $sendflag = 0; |
|
my $append_to_subj; |
|
my $header; |
|
my @chg_package; |
|
# |
|
# Execute apt-get command to update distributions |
|
system ("$apt update > /dev/null"); |
|
my $returnvalue = $?>>8; |
|
if ($returnvalue == 0) { |
|
# Execute apt-get commands to check for upgrades |
|
if (open (PIPE, "$apt -y --dry-run upgrade 2>&1 |")) { |
|
my @output=<PIPE>; |
|
close(PIPE); |
|
chomp(@output); |
|
foreach my $line (@output) { |
|
$line =~ s/^\s+//; |
|
my @items = split(/\s+/,$line); |
|
if ($items[0] eq "Inst") { |
|
push(@chg_package,$items[1]); |
|
} |
|
} |
|
if (@chg_package > 0) { |
|
$header = 'apt-get upgrade found the following packages need updating:'. |
|
"\n\n"; |
|
open(TMPFILE,">>$tmpfile"); |
|
my $message = join("\n",@output); |
|
print TMPFILE $header.$message; |
|
close(TMPFILE); |
|
$append_to_subj= ' deb packages to upgrade'; |
|
$sendflag = 1; |
|
} |
|
} else { |
|
$append_to_subj = ' Error running deb upgrade check'; |
|
$sendflag = 1; |
|
} |
|
} else { |
|
$append_to_subj = ' Error running deb update check'; |
|
$sendflag = 1; |
|
} |
|
return ($sendflag,$append_to_subj); |
} |
} |
|
|
sub check_with_checkrpms { |
sub check_with_checkrpms { |