1833189 Members
2848 Online
110051 Solutions
New Discussion

Shell errors

 
Sivasingam Santhakumar
Frequent Advisor

Shell errors

Dear gurus,

How can trap shell messages (stdout/stderr) into a perl script?.

For example:

I want to trap my faild jobs (in cron) and email me using perl script.
I don't want cron to send me mail for security reasons.

Thanks
2 REPLIES 2
Mark Grant
Honored Contributor

Re: Shell errors

Well, you could pipe the output into a perl script with something like this.

scriptname.sh 2>&1 | perl_script.pl

This will work with cron or anything else in fact.

If the perl script reads it will get both the errors and the normal output in the above case.

Never preceed any demonstration with anything more predictive than "watch this"
Bill Thorsteinson
Honored Contributor

Re: Shell errors

Try somethink like

command 2> /tmp/$$.err || \
errorMail.pl /tmp/$$.err
rm $$.err

This will send the stderr output if command
exits with an error status.

Or

command 2> /tmp/$$.err
[ -s /tmp/$$.err ] && errorMail.pl /tmp/$$.err
rm $$.err

This will send an email if you have output on
stderr.