0

I have a cron job that is running every hour, and providing output (over stdout) similar to the following:

Found 1 batch jobs
{'job': 'update'}
Job 1 started at 2013-06-07 13:00:03.673683+00:00
Waiting for 1 batch jobs to complete
Job 1 completed at 2013-06-07 13:57:56+01:00

Now, this is all handy info, but I don't particularly want it emailed to me every hour. The app is set up to print the above info to stdout, and any warnings or errors to stderr. Is it possible to log the above to a file (ie. /var/log somewhere), but email me any text that comes through over stderr?

Joel Cross
  • 103
  • 2
  • So, a bit of further information in case it's not obvious: the above cron was set up using the `crontab` command, and the email is sent using crontab's `MAILTO` environment variable. – Joel Cross Jun 07 '13 at 13:35

1 Answers1

1

Just redirect the command stdout output using ">> /var/log/whatever.log"

if there is no stderr output there will be no mail from cron and if there is stderr you will receive an email because stderr is not redirected to the file.

Pascal Schmiel
  • 1,738
  • 12
  • 17