Operating System - HP-UX
1833772 Members
2009 Online
110063 Solutions
New Discussion

How to stop cron jobs sending long messages to root mailbox?

 
Jan Shu
Regular Advisor

How to stop cron jobs sending long messages to root mailbox?

Hi All,

Some of my root cronjobs send long output messages to the root mailbox. E.g. there is a cronjob to tar a user log direcoty, and it sent long file lists to root mail. DBAs had similar issue. How to stop the cron jobs sending long outputs to the root/oracle mailboxes?

Here is one script that sends long message:
rm /orapp6/bak/users.tar*
tar -cvf /orapp6/bak/users.tar /u202/app/users
compress /orapp6/bak/users.tar

The message is like following:
a /u202/app/users/astreet/.cshrc 3 blocks
a /u202/app/users/astreet/.exrc 1 blocks
a /u202/app/users/astreet/.login 1 blocks
a /u202/app/users/astreet/.profile 1 blocks
a /u202/app/users/astreet/.rhosts 1 blocks
a /u202/app/users/brussell/.cshrc 3 blocks
a /u202/app/users/brussell/.exrc 1 blocks
a /u202/app/users/brussell/.login 1 blocks
a /u202/app/users/brussell/.profile 1 blocks
a /u202/app/users/brussell/.rhosts 1 blocks
This goes on for thousands lines...

*************************************************
Cron: The previous message is the standard output and standard error of one of your crontab commands:

/var/adm/scripts/oclog



Thank you.
Best Regards,
Jan Shu
3 REPLIES 3
Rick Garland
Honored Contributor

Re: How to stop cron jobs sending long messages to root mailbox?

You can redirect the output to /dev/null
(Example cron entry)
00 12 * * * yourcommand 2>&1 > /dev/null

But then if a problem arises you do not have the error.

Another option, test for the return value of the command. If successful and return is 0, send an email saying "SUCCESS", else send mail saying "FAILED"

harry d brown jr
Honored Contributor

Re: How to stop cron jobs sending long messages to root mailbox?

Redirect the STDOUT and STDERR to a file/log name:

0 12 * * * /usr/sbin/icod_notify -c 2>&1 1>/var/adm/syslog/backups.log

live free or die
harry d brown jr
Live Free or Die
Jan Shu
Regular Advisor

Re: How to stop cron jobs sending long messages to root mailbox?

Thanks for your help.

Regards,
Jan