Script cron: list failed command

Martin Gerdes <[email protected]>
Newsgroups gmane.comp.log.logwatch.devel
Message-ID <[email protected]>
Sorry for the late reply - was on vacation for 2 weeks.

/usr/share/logwatch/scripts/services# diff -u cron.bak cron

--- cron.bak    2011-03-04 08:55:02.000000000 +0100
+++ cron        2012-09-07 13:55:42.000000000 +0200
@@ -118,6 +118,7 @@
  $Reloads = 0;
  $MailErrors = 0;
  $BFMFile = 0;
+%ExecutedCommand = ();

  while (defined($ThisLine = <STDIN>)) {
     chomp($ThisLine);
@@ -139,13 +140,15 @@
     ) {
        # Ignore
     } elsif (
-      ($ThisLine =~ s/^([^ ]+) \([^ ]+\)\s+//) or
-      ($ThisLine =~ 
s/^\S+\s+\S+\s+..:..:..\s+\S+\s+\S+\[\d+\]:\s+\((\S+)\)\s+//)
+      #($ThisLine =~ s/^([^ ]+) \([^ ]+\)\s+//) or
+      ($ThisLine =~ 
s/^\S+\s+\S+\s+..:..:..\s+\S+\s+\S+\[(\d+)\]:\s+\((\S+)\)\s+//)
     ) {
-      $User = $1;
+      $PID  = $1;
+      $User = $2;

        if ($ThisLine =~ s/^CMD \((.+)\)\s*$/$1/) {
           $Runs->{$User}->{$ThisLine}++;
+         $ExecutedCommand{$PID} = {command=>$ThisLine, user=>$User};
        } elsif ($ThisLine =~ s/^CMD FINISH \((.+)\)\s*$/$1/) {
           $Runs->{$User}->{$ThisLine}++;
        } elsif ($ThisLine =~ s/^(END|CMD START) \((.+)\)\s*$/$1/) {
@@ -175,6 +178,9 @@
                    $ThisLine =~ /session closed/ ) {
           # ignore
        } elsif ( ($Reason) = ($ThisLine =~ /^error \((.+)\)$/) ) {
+         if ($Reason =~ /^grandchild #(\d+) failed with exit status 
(\d+)/ && $ExecutedCommand{                     $1}) {
+             $Reason = $ExecutedCommand{$1}{user}.": failed command (EC 
".$2."): ".$ExecutedCom                     mand{$1}{command};
+         }
           $Errors{$Reason}++;
        } elsif ( ($FileName) = ($ThisLine =~ /BAD FILE MODE \((.+)\)/) ) {
           $BFMFile{$FileName}++;


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.