Operating System - Tru64 Unix
1827474 Members
2370 Online
109965 Solutions
New Discussion

Re: limiting crons output into e-mail

 
keith demingware
Occasional Advisor

limiting crons output into e-mail

I am running cron in hpux 11.00. I run many jobs out of cron each night. I want to limit the size of the output that reaches my mail system. I would like to just see say the first ten lines of each mail message that is received instead of say 100 lines of a particular process that runs each night. I hope this makes sense.
just when you thought you had the answer
2 REPLIES 2
Ivan Ferreira
Honored Contributor

Re: limiting crons output into e-mail

I think that you best option is to avoid the output of messages from your cron process to STDOUT and STDERRS. Redirect it to a log file and then mail the contents of the N lines of file, for example:

# cat job1.sh

LOGFILE=/tmp/job1.log
find / -ls > $LOGFILE 2>&1
head -10 $LOGFILE | mailx -s "Job1 Finished" user@domain.com


In this case, if job1.sh is executed by cron, will run and redirecto all output to a log file, then in your mail you will have only 10 lines of the logfile.
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
Fabrice Rafart
New Member

Re: limiting crons output into e-mail

Hello,

You can also try in your crontab :

x x x x x cmd 2>&1 | head -10

Best regards,