[LON-CAPA-cvs] cvs: loncom /build CHECKRPMS
raeburn
raeburn at source.lon-capa.org
Sun Jul 5 19:28:46 EDT 2026
raeburn Sun Jul 5 23:28:46 2026 EDT
Modified files:
/loncom/build CHECKRPMS
Log:
- clusterstatus.pl expects /home/httpd/html/lon-status/checkrpms.txt to
contain single line: time=<timestamp>&status=<status>&rpmcount=<count>
[ <status> is fail, update or ok, <count> is number of outdated packages ]
-------------- next part --------------
Index: loncom/build/CHECKRPMS
diff -u loncom/build/CHECKRPMS:1.20 loncom/build/CHECKRPMS:1.21
--- loncom/build/CHECKRPMS:1.20 Thu Oct 24 16:38:32 2024
+++ loncom/build/CHECKRPMS Sun Jul 5 23:28:46 2026
@@ -3,7 +3,7 @@
# The LearningOnline Network with CAPA
# Checks status of RPM packages on system.
#
-# $Id: CHECKRPMS,v 1.20 2024/10/24 16:38:32 raeburn Exp $
+# $Id: CHECKRPMS,v 1.21 2026/07/05 23:28:46 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -93,86 +93,89 @@
}
}
-my ($cmd,$send,$addsubj);
+my ($cmd,$send,$addsubj,$simplestr);
if ($distro =~ /^fedora(\d+)$/) {
my $version =$1;
if ($version > 21) {
$cmd = 'dnf update';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_yum_or_dnf($tmpfile,'dnf');
+ ($send,$addsubj,$simplestr) = &check_with_yum_or_dnf($tmpfile,'dnf');
} else {
$cmd = 'yum update';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_yum_or_dnf($tmpfile,'yum');
+ ($send,$addsubj,$simplestr) = &check_with_yum_or_dnf($tmpfile,'yum');
}
} elsif ($distro =~ /^(suse|sles)9\.?\d?$/) {
$cmd = 'you';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_you($tmpfile);
+ ($send,$addsubj,$simplestr) = &check_with_you($tmpfile);
} elsif ($distro =~ /^suse(\d{2,})\.(\d+)$/) {
my $version =$1;
my $subversion = $2;
if (($version > 10) || (($version == 10) && ($subversion > 1))) {
$cmd = 'zypper up';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_zypper($tmpfile);
+ ($send,$addsubj,$simplestr) = &check_with_zypper($tmpfile);
} else {
$cmd = 'rug up';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_rug($tmpfile);
+ ($send,$addsubj,$simplestr) = &check_with_rug($tmpfile);
}
} elsif ($distro =~ /^sles10$/) {
$cmd = 'rug up';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_rug($tmpfile);
+ ($send,$addsubj,$simplestr) = &check_with_rug($tmpfile);
} elsif ($distro =~ /^sles(\d+)$/) {
$cmd = 'zypper up';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_zypper($tmpfile);
+ ($send,$addsubj,$simplestr) = &check_with_zypper($tmpfile);
} elsif ($distro =~ /^rhes(\d+)$/) {
my $version = $1;
if ($version == 4) {
$cmd ='up2date -u --nox';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_up2date($tmpfile);
+ ($send,$addsubj,$simplestr) = &check_with_up2date($tmpfile);
} elsif ($version <= 7) {
$cmd = 'yum update';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_yum_or_dnf($tmpfile,'yum');
+ ($send,$addsubj,$simplestr) = &check_with_yum_or_dnf($tmpfile,'yum');
} else {
$cmd = 'dnf update';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_yum_or_dnf($tmpfile,'dnf');
+ ($send,$addsubj,$simplestr) = &check_with_yum_or_dnf($tmpfile,'dnf');
}
} elsif ($distro =~ /^(?:centos|scientific|oracle|rocky|alma)(\d+)$/) {
my $version = $1;
if ($version <= 7) {
$cmd = 'yum update';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_yum_or_dnf($tmpfile,'yum');
+ ($send,$addsubj,$simplestr) = &check_with_yum_or_dnf($tmpfile,'yum');
} else {
$cmd = 'dnf update';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_yum_or_dnf($tmpfile,'dnf');
+ ($send,$addsubj,$simplestr) = &check_with_yum_or_dnf($tmpfile,'dnf');
}
} elsif ($distro =~ /^(debian|ubuntu)\d+/) {
$cmd = 'apt-get upgrade';
&prepare_msg($tmpfile,$cmd);
- ($send,$addsubj) = &check_with_apt($tmpfile);
+ ($send,$addsubj,$simplestr) = &check_with_apt($tmpfile);
} else {
- $cmd = '/usr/local/bin/check-rpms --update';
- ($send,$addsubj) = &check_with_checkrpms($tmpfile);
+ $cmd = '/usr/local/loncapa/bin/check-rpms --update';
+ ($send,$addsubj,$simplestr) = &check_with_checkrpms($tmpfile);
}
if ($send) {
$subj .= $addsubj;
- if ($docroot ne '') {
- system("cat $tmpfile > $docroot/lon-status/checkrpms.txt");
+ system(qq{mail -s '$subj' "$emailto" < $tmpfile});
+}
+if ($docroot ne '') {
+ if (open(my $fh,'>',"$docroot/lon-status/checkrpms.txt")) {
+ print $fh $simplestr;
+ close($fh);
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});
}
sub prepare_msg {
@@ -199,20 +202,25 @@
my $you = '/usr/bin/online_update';
my $sendflag = 0;
my $append_to_subj;
+ my $simplestr = 'time='.time.'&status=';
if (open (PIPE, "$you -k -len 2>&1 |")) {
my $output=<PIPE>;
close(PIPE);
chomp $output;
- unless ($output eq 'No updates available.') {
+ if ($output eq 'No updates available.') {
+ $simplestr.= 'ok&rpmcount=0';
+ } else {
if (open (PIPE, "$you -s -d -len |grep ^INSTALL |")) {
my @updates = <PIPE>;
close(PIPE);
+ my $rpmcount = 0;
my $allpackages;
foreach my $line (@updates) {
my $package = substr($line,rindex($line,'/')+1);
if ($package ne '') {
$allpackages .= $package;
+ $rpmcount ++;
}
}
if ($allpackages ne '') {
@@ -222,16 +230,23 @@
$sendflag = 1;
$append_to_subj = ' RPMS to upgrade';
}
+ if ($rpmcount) {
+ $simplestr.= 'update&rpmcount='.$rpmcount;
+ } else {
+ $simplestr.= 'ok&rpmcount=0';
+ }
} else {
$sendflag = 1;
$append_to_subj = ' Error running RPM update script';
+ $simplestr.= 'fail&rpmcount=';
}
}
} else {
$sendflag = 1;
$append_to_subj = ' Error running RPM update script';
+ $simplestr.= 'fail&rpmcount=';
}
- return ($sendflag,$append_to_subj);
+ return ($sendflag,$append_to_subj,$simplestr);
}
sub check_with_yum_or_dnf {
@@ -254,16 +269,43 @@
#
# Determine status of yum or dnf run
+ my $simplestr = 'time='.time.'&status=';
if (100 == $returnvalue) {
$sendflag = 1;
$append_to_subj = ' RPMS to upgrade';
+ my $rpmcount = 0;
+ my $basearch;
+ if (open(PIPE, 'rpm -q --qf "%{arch}" -f /etc/redhat-release 2>/dev/null |')) {
+ $basearch = <PIPE>;
+ close(PIPE);
+ }
+ if (open(my $fh,'<',$tmpfile)) {
+ while (my $line=<$fh>) {
+ next if ($line =~ /^Security:/);
+ if ($basearch ne '') {
+ if ($line =~ /\Q.$basearch\E\s+/) {
+ $rpmcount ++;
+ }
+ }
+ if ($line =~ /\Q.noarch\E\s+/) {
+ $rpmcount ++;
+ }
+ }
+ }
+ if ($rpmcount) {
+ $simplestr.= 'update&rpmcount='.$rpmcount;
+ } else {
+ $simplestr.= 'ok&rpmcount=0';
+ }
} elsif (0 != $returnvalue) {
$sendflag = 1;
$append_to_subj = ' Error running RPM update script';
+ $simplestr.= 'fail&rpmcount=';
} else {
# yum or dnf returned 0, so everything is up to date.
+ $simplestr.= 'ok&rpmcount=0';
}
- return ($sendflag,$append_to_subj);
+ return ($sendflag,$append_to_subj,$simplestr);
}
sub check_with_up2date {
@@ -271,10 +313,11 @@
my $up2date = '/usr/bin/up2date-nox';
my $sendflag = 0;
my $append_to_subj;
- #
+ my $simplestr = 'time='.time.'&status=';
+
# Execute online_update command to check for updates
my $up2date_error = 1;
- if (open (PIPE, "$up2date -l 2>&1 |")) {
+ if (open(PIPE, "$up2date -l 2>&1 |")) {
my @result=<PIPE>;
close(PIPE);
my $output;
@@ -288,24 +331,34 @@
if (@result > 0) {
if ($output =~ /Fetching Obsoletes list/) {
$up2date_error = 0;
+ my $rpmcount = 0;
if ($output =~ /Name\s+Version\s+Rel\s+[\n\r\f]+\-+[\n\r\f]+(.+)/s) {
my $packagelist = $1;
if ($packagelist ne '' && $packagelist !~ /^[\s\n\r\f]+$/) {
open(TMPFILE,">>$tmpfile");
print TMPFILE $packagelist;
close(TMPFILE);
+ $rpmcount ++; #FIXME
$append_to_subj = ' RPMS to upgrade';
$sendflag = 1;
}
}
+ if ($rpmcount) {
+ $simplestr.= 'update&rpmcount='.$rpmcount;
+ } else {
+ $simplestr.= 'ok&rpmcount=0';
+ }
}
+ } else {
+ $simplestr.= 'ok&rpmcount=0';
}
}
if ($up2date_error) {
$append_to_subj = ' Error running RPM update script';
$sendflag = 1;
+ $simplestr.= 'fail&rpmcount=';
}
- return ($sendflag,$append_to_subj);
+ return ($sendflag,$append_to_subj,$simplestr);
}
sub check_with_rug {
@@ -313,7 +366,8 @@
my $rug = '/usr/bin/rug';
my $sendflag = 0;
my $append_to_subj;
- #
+ my $simplestr = 'time='.time.'&status=';
+
# Execute rug command to check for updates
if (open (PIPE, "$rug up -N 2>&1 |")) {
my @output=<PIPE>;
@@ -347,12 +401,16 @@
close(TMPFILE);
$append_to_subj= ' RPMS to upgrade';
$sendflag = 1;
+ $simplestr.= 'update&rpmcount='.scalar(@clean_output);
+ } else {
+ $simplestr.= 'ok&rpmcount=0';
}
} else {
$append_to_subj = ' Error running RPM update check';
$sendflag = 1;
+ $simplestr.= 'fail&rpmcount=';
}
- return ($sendflag,$append_to_subj);
+ return ($sendflag,$append_to_subj,$simplestr);
}
sub check_with_zypper {
@@ -360,8 +418,9 @@
my $zypper = '/usr/bin/zypper';
my $sendflag = 0;
my $append_to_subj;
+ my $simplestr = 'time='.time.'&status=';
my $header;
- #
+
# Execute zypper command to check for updates
if (open (PIPE, "$zypper lu 2>&1 |")) {
my @output=<PIPE>;
@@ -396,12 +455,16 @@
close(TMPFILE);
$append_to_subj= ' RPMS to upgrade';
$sendflag = 1;
+ $simplestr.= 'update&rpmcount='.scalar(@clean_output);
+ } else {
+ $simplestr.= 'ok&rpmcount=0';
}
} else {
$append_to_subj = ' Error running RPM update check';
$sendflag = 1;
+ $simplestr.= 'fail&rpmcount=';
}
- return ($sendflag,$append_to_subj);
+ return ($sendflag,$append_to_subj,$simplestr);
}
sub check_with_apt {
@@ -409,9 +472,10 @@
my $apt = '/usr/bin/apt-get';
my $sendflag = 0;
my $append_to_subj;
+ my $simplestr = 'time='.time.'&status=';
my $header;
my @chg_package;
- #
+
# Execute apt-get command to update distributions
system ("$apt update > /dev/null");
my $returnvalue = $?>>8;
@@ -437,23 +501,29 @@
close(TMPFILE);
$append_to_subj= ' deb packages to upgrade';
$sendflag = 1;
+ $simplestr.= 'update&rpmcount='.scalar(@output);
+ } else {
+ $simplestr.= 'ok&rpmcount=0';
}
} else {
$append_to_subj = ' Error running deb upgrade check';
$sendflag = 1;
+ $simplestr.= 'fail&rpmcount=';
}
} else {
$append_to_subj = ' Error running deb update check';
$sendflag = 1;
+ $simplestr.= 'fail&rpmcount=';
}
- return ($sendflag,$append_to_subj);
+ return ($sendflag,$append_to_subj,$simplestr);
}
sub check_with_checkrpms {
my ($tmpfile,$perlvar) = @_;
- my $checkrpms = '/usr/local/bin/check-rpms';
+ my $checkrpms = '/usr/local/loncapa/bin/check-rpms';
my $sendflag = 0;
my $append_to_subj;
+ my $simplestr = 'time='.time.'&status=';
# Run Martin Seigert's checkrpms script. See
# See http://www.sfu.ca/acs/security/linux/check-rpms.html
@@ -471,13 +541,15 @@
END
$append_to_subj = ' Error running RPM update check';
- $sendflag = 1;
+ $sendflag = 1;
+ $simplestr .= 'fail&rpmcount=';
} else {
#
# Run check-rpms and capture its output
if (open (PIPE, "$checkrpms 2>&1 |")) {
my $output=<PIPE>;
close(PIPE);
+ my $rpmcount = 0;
if ($output ne '') {
$output = <<"END";
@@ -504,9 +576,15 @@
print TMPFILE $output;
close(TMPFILE);
$append_to_subj = ' RPMS to upgrade';
- $sendflag = 1;
+ $sendflag = 1;
+ $rpmcount ++; #FIXME
+ $simplestr .= 'update&rpmcount='.$rpmcount;
+ } else {
+ $simplestr .= 'ok&rpmcount=0';
}
+ } else {
+ $simplestr .= 'fail&rpmcount=';
}
}
- return ($sendflag,$append_to_subj);
+ return ($sendflag,$append_to_subj,$simplestr);
}
More information about the LON-CAPA-cvs
mailing list