Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

My crontab:

PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=admins@boingoboingo.com
HOME=/
LD_LIBRARY_PATH=/usr/local/lib/
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7)  OR
#sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  *  command to be executed
05 01 * * * /root/backup_scripts/run_backups.sh
45 03 * * * /root/backup_scripts/new_scripts/run.sh> "/root/backup_scripts/new_scripts/$(date).run.log" 2>&1

I DO get daemon emails with the run_backups.sh job

I do NOT get daemon emails with the run.sh job, yet I verified it does run

Here's the daemon email for the run_backups.sh:

    from    Cron Daemon <root@aapsan01.boingoboingo.local>
to  admins@boingoboingo.com
date    Thu, Sep 30, 2010 at 2:22 AM
subject Cron <root@aapsan01> /root/backup_scripts/run_backups.sh
mailing list    <admins.boingoboingo.com> Filter messages from this mailing list
mailed-by   boingoboingo.com
hide details 2:22 AM (7 hours ago)
[09/30/10 01:05:01] mounting the usb drive
[09/30/10 01:05:09] usbdrive1 is ready.
[blah]blah, blah blah.
[09/30/10 06:41:51] finished syncing drives.
[09/30/10 06:41:53] usbdrive1 was disconnected.
share|improve this question

2 Answers 2

up vote 3 down vote accepted

Emails are a result of data going to STDOUT or STDERR from your cron job. The cron job in question has had both redirected to the log file.

> "/root/backup_scripts/new_scripts/$(date).run.log" 2>&1
^ redirect STDOUT to file ^                          ^^^^ redirect STDERR to SDTOUT 
share|improve this answer
    
While the other answer was helpful, yours spelled it out succinctly. Thank you. –  Flotsam N. Jetsam Sep 30 '10 at 17:19

After you redirect the standard output of run.sh to /root/backup_scripts/new_scripts/$(date).run.log there is only the error output left to redirect to standard out. Could it be that run.sh just doesn't produce any errors?

If you want to see the standard output of run.sh use tee to save it to file, too.

45 03 * * * /root/backup_scripts/new_scripts/run.sh | tee "/root/backup_scripts/new_scripts/$(date).run.log" 2>&1
share|improve this answer
    
Are you saying my redirect is stopping the daemon email? –  Flotsam N. Jetsam Sep 30 '10 at 14:31
    
@Flotsam: No, I was saying that your command (with redirects etc) just produces no output. –  Benjamin Bannier Sep 30 '10 at 14:32
    
Ok, so the daemon emails only send on error? It is true that the log file is empty and therefore there are no errors, yet I thought the daemon emailed regardless. –  Flotsam N. Jetsam Sep 30 '10 at 14:45
    
@Flotsam: It only sent on error because you redirected stout to a file and there is nothing left in the stdout stream. And AFAIK cron is not sending empty ouputs just for kicks. –  Benjamin Bannier Sep 30 '10 at 14:56
    
@honk: You're saying (I think) that stderr is not redirected, but it is (2>&1). –  Dennis Williamson Sep 30 '10 at 15:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.