I have a cron job running a script which takes about 6 hours to finish. The problem is that cron is not mailing me the output of that job, and I would like it to.

I have it in /etc/crontab and it's something like:

0 *    * * *   myuser    /usr/local/bin/my-script

Yes, this run's it every hour, but there is a lock-file in the script, so if the previous run didn't finish, the new run of the script will quit immediately without doing anything.

The system is Debian 5.0 'lenny', and the MTA is Postfix.

If the job is killed (with "kill $PID") early during its run, then I do get an e-mail with the output of the job. Also if I modify the script to do 10 times less stuff, then I also do get an e-mail. Its only if the script is running for some hours I do not get an e-mail at all.

Relevant lines of ps afx a short time after the cron job starts:

 8222 ?        Ss     0:04 /usr/sbin/cron
13265 ?        S      0:00  \_ /USR/SBIN/CRON
13297 ?        Ss     0:00      \_ /bin/bash /usr/local/bin/my-script
13395 ?        S      0:16      |   \_ /usr/bin/python /usr/local/bin/some-script.py
17065 ?        S      0:00      \_ /usr/sbin/sendmail -i -FCronDaemon -oem myuser
17066 ?        S      0:00          \_ /usr/sbin/postdrop -r

So it seems that the MTA is already called when the cron job starts, not when it finishes. Can that be related to the problem? Might it be possible that Postfix doesn't like postdrop running so long, and it times-out or something? How can I solve the issue - I need to have the output e-mailed to me.

  • can you post logs from your /var/log/mail.log
    – Mike
    May 15, 2011 at 2:07
  • @Mike: there is nothing in my /var/log/mail.log about mail from cron. Even when I do get an e-mail from a cron job, there is still nothing about that in my /var/log/mail.log - only mail to or from remote servers is logged there, local mail is not.
    – ria
    May 15, 2011 at 2:13

1 Answer 1


As a workaround: redirect output to a file and mail it from inside of your cron script?

As a debug tool: run from cron a series of scripts that just print a date, print their name, intended lenght of sleep, sleep for n minutes, print a date, and then quit. I would run them all at the same time, to have answer in 7 hours. If you test sleep times of length from 1h to 7 hours with, let's say, 10 mins increment, you'll know if it's a general time-out issue, or something to do just with your script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .