1820473 Members
3236 Online
109624 Solutions
New Discussion юеВ

Cron Email Messages

 
Michael Gretton
Frequent Advisor

Cron Email Messages

To All:

I would like to thank everyone who has helped me in the past. This site is a valuable tool and has saved me many times.

I have anoying and perhaps stupid problem. We have about 20 or 30 crons that run each day on several machines and I get emailed (root gets emailed) after each cron completes. I still want to get these emails, however, it would be helpful if I could stop cron from sending them right away and having it send them to a file and then at the end of the night send just one email with all the results. Is this doable? What do other people do to cut down on message traffic? it sends output from the cron and adds this to the bottom:
***********************************************
Cron: The previous message is the standard output
and standard error of one of your crontab commands:


I am running hp 10.20.


Mike
4 REPLIES 4
Thierry Poels_1
Honored Contributor

Re: Cron Email Messages

Hi,

cron mails you all stdout and stderr output generated by the cronjob.
You could edit each script and redirect all output to one or more files. An other option is to edit the crontab and redirect output of each script there.

e.g.: 0 8 * * * script > /tmp/log1 2> /tmp/log2

regards,
Thierry
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Andreas Voss
Honored Contributor

Re: Cron Email Messages

Hi,

Thierry has a good idea, here some more idieas.

schedule a cron job before all other that clears the summary log file ie:

0 18 * * * rm -f /tmp/cron.log

Now redirect the output of all your cron jobs as Thierry said.

schedule a cron job after all other that mails the summary log file ie:

0 8 * * * cat /tmp/cron.log | mailx -s 'cron summary'

Regards
Satish Y
Trusted Contributor

Re: Cron Email Messages

Hi Michael,

One more idea,

You can send the output of each cronjob to a temporary log file and then u put an entry after last cron job to mail that file. for example,

Assuming that u have scheduled last job at 23hrs:

00 00 * * * job1 > /tmp/maillog1 2> /tmp/maillog2
00 01 * * * job2 >> /tmp/maillog1 2>> /tmp/maillog2
..............
..............
00 23 * * * (job24 >> /tmp/maillog1 2>> /tmp/maillog2; cat /tmp/mailog1 /tmp/maillog2 | mailx -s "subject" )


Cheers...
Satish.
Difference between good and the best is only a little effort
Michael Gretton
Frequent Advisor

Re: Cron Email Messages

THANK YOU..VERY SIMPLE SOLUTIONS!!!

Good site!