--- loncom/loncron 2019/07/18 18:28:40 1.119 +++ loncom/loncron 2020/05/06 13:34:22 1.122 @@ -2,7 +2,7 @@ # Housekeeping program, started by cron, loncontrol and loncron.pl # -# $Id: loncron,v 1.119 2019/07/18 18:28:40 raeburn Exp $ +# $Id: loncron,v 1.122 2020/05/06 13:34:22 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -495,19 +495,38 @@ sub clean_lonIDs { my $cleaned=0; my $active=0; while (my $fname=<$perlvar{'lonIDsDir'}/*>) { - my ($dev,$ino,$mode,$nlink, - $uid,$gid,$rdev,$size, - $atime,$mtime,$ctime, - $blksize,$blocks)=stat($fname); - my $now=time; - my $since=$now-$mtime; - if ($since>$perlvar{'lonExpire'}) { - $cleaned++; - &log($fh,"Unlinking $fname
"); - unlink("$fname"); - } else { - $active++; - } + my $now=time; + if (-l $fname) { + my $linkfname = readlink($fname); + if (-f $linkfname) { + if ($linkfname =~ m{^$perlvar{'lonIDsDir'}/[^/]+\.id$}) { + my @data = stat($linkfname); + my $mtime = $data[9]; + my $since=$now-$mtime; + if ($since>$perlvar{'lonExpire'}) { + if (unlink($linkfname)) { + $cleaned++; + &log($fh,"Unlinking $linkfname
"); + unlink($fname); + } + } + } + } else { + unlink($fname); + } + } elsif (-f $fname) { + my @data = stat($fname); + my $mtime = $data[9]; + my $since=$now-$mtime; + if ($since>$perlvar{'lonExpire'}) { + if (unlink($fname)) { + $cleaned++; + &log($fh,"Unlinking $fname
"); + } + } else { + $active++; + } + } } &log($fh,"

Cleaned up ".$cleaned." stale session token(s).

"); &log($fh,"

$active open session(s)

"); @@ -1096,7 +1115,7 @@ sub write_hostips { if (keys(%prevhosts) && keys(%currhosts)) { foreach my $key (keys(%prevhosts)) { unless ($currhosts{$key} eq $prevhosts{$key}) { - $ipchange{$key} = $prevhosts{$key}.'|'.$currhosts{$key}; + $ipchange{$key} = $prevhosts{$key}.' | '.$currhosts{$key}; } } foreach my $key (keys(%currhosts)) { @@ -1109,10 +1128,10 @@ sub write_hostips { if (keys(%ipchange)) { if (open(my $fh,'>>',$perlvar{'lonDaemons'}.'/logs/hostip.log')) { print $fh "********************\n".localtime(time).' Changes --'."\n". - "Hostname | Previous IP | New IP\n". - "--------------------------------\n"; + "| Hostname | Previous IP | New IP |\n". + " --------------------------------- \n"; foreach my $hostname (sort(keys(%ipchange))) { - print $fh "$hostname | $ipchange{$hostname}\n"; + print $fh "| $hostname | $ipchange{$hostname} |\n"; } print $fh "\n*******************\n\n"; close($fh); @@ -1127,10 +1146,10 @@ sub write_hostips { "MIME-Version: 1.0\n\n". "Host/IP changes\n". " \n". - "Hostname | Previous IP | New IP\n". - "--------------------------------\n"; + "| Hostname | Previous IP | New IP |\n". + " --------------------------------- \n"; foreach my $hostname (sort(keys(%ipchange))) { - $chgmail .= "$hostname | $ipchange{$hostname}\n"; + $chgmail .= "| $hostname | $ipchange{$hostname} |\n"; } $chgmail .= "\n\n"; if (open(my $mailh, "|/usr/lib/sendmail -oi -t -odb")) {