0

This is a ridiculous newbie question, sorry!

I am running a (Python) script regularly using cron.

I would like to log the output to a logfile, and I would like to be emailed with any errors that occur if the script does not complete.

Currently my thoughts are: write a shell script which runs the script, and outputs the result to a log, and emails me if there are errors. Then run that shell script from cron.

But is there anything inbuilt in cron that would do some of this for me?

Would be handy if so.

Thanks.

Richard
  • 955
  • 5
  • 13
  • 16

2 Answers2

2

cron already emails the output of the job to the owner of the cron job if not directed otherwise. Use tee if you also want to redirect it to a file.

n0pe
  • 16,472
  • 18
  • 71
  • 102
Ignacio Vazquez-Abrams
  • 111,361
  • 10
  • 201
  • 247
  • @MaxMackie: Did you mean `crond`? – Ignacio Vazquez-Abrams Jul 09 '11 at 20:38
  • I don't think I edited out any letters, I just surrounded it with code tags. My bad if I did. – n0pe Jul 09 '11 at 20:54
  • This would be a useful answer if you took a second to explain exactly *who* the recipient is, and how to access or forward these emails. There's a reason [this question](http://superuser.com/questions/306163/what-is-the-you-have-new-mail-message-in-linux-unix) is so popular. – Daniel Beck Jul 09 '11 at 21:03
  • @MaxMackie: Usually commands are surrounded by code tags, not application names. – Ignacio Vazquez-Abrams Jul 09 '11 at 21:31
  • Sorry, you can remove them if you like. I find it more legible to add code tags around applications like that. Easier to spot them and adds emphasis. – n0pe Jul 09 '11 at 22:10
0

Be careful that your job doesn't generate any output if you use that method, otherwise you'll find yourself ignoring the emails by the time something does go wrong. The unix tool philosophy of "no news is good news" developed for a reason.

Stephanie
  • 2,298
  • 15
  • 18