Script cron: list failed command
Martin Gerdes <[email protected]>
| Newsgroups | gmane.comp.log.logwatch.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi List!
Just wanted to let you know that I scratched an itch I had with the
'cron' script of lowatch.
I did not like it that I had to look up in the logfiles what the problem
was every time I saw something like 'grandchild #15555 failed with exit
status 1: 1 Time(s)' in the summary generated by logwatch.
So I took a look at /usr/share/logwatch/scripts/services/cron as
provided by Debian Squeeze (7.3.6.cvs20090906-1squeeze1), and modified
it as follows (diff output):
120a121
> %ExecutedCommand = ();
142,143c143,144
< ($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+//)
145c146,147
< $User = $1;
---
> $PID = $1;
> $User = $2;
148a151
> $ExecutedCommand{$PID} = {command=>$ThisLine, user=>$User};
177a181,183
> if ($Reason =~ /^grandchild #(\d+) failed with exit status
(\d+)/ && $ExecutedCommand{$1}) {
> $Reason = $ExecutedCommand{$1}{user}.": failed command
(EC ".$2."): ".$ExecutedCommand{$1}{command};
> }
I have commented out the other style of logfile formatting since I don't
use it and because of that, would not know where it tells the PID.
This changes the output in the logwatch summery to something like:
Errors when running cron:
marko: failed command (EC 1): cd; ./compareCashAccounts.sh | grep
f: 7 Time(s)
Which helps me a lot more than the PID of the failed process (if I need
that, I am still free to look through the log file myself). And the
output is shorter besides :-) (in the old style, that would be 7 lines
of errors...).
Just in case anyone else is interested in the improvement.
Kind regards,
Martin Gerdes
DSER
------------------------------------------------------------------------------
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/