views:

95

answers:

3

I have followed the suggestion in this question

as I am using Django, I have set the script to store date and time of each run of the script in the db, but no entry has been stored yet in the database.


Is there a way to figure out, other than typing "top" and searching through?

+5  A: 

First, I would probably configure cron to mail yourself any output by using MAILTO:

In /etc/crontab:

MAILTO=username

Second, I usually add something to my script that (almost) cannot possibly fail, like the following:

#!/bin/sh
echo "$0 ran on `date +%c`" >> /tmp/crontab_test.log

# ... rest of program

If you're calling a python script directly from cron, you could do something similar or create a wrapper shell script.

Kaleb Pederson
@Kaleb thank you very much indeed! I have edited /etc/crontab, and added [email protected]. No emails yet, I think the script fails half way through.
RadiantHex
Make sure you run `newaliases` as alfredodeza pointed out. I've never tried to send it to anything but a local user account, so I'm not positive you can. The docs say it's "sent to the user so named."
Kaleb Pederson
also, make sure it's not being picked up by the spam filter
cobbal
If it wasn't clear, you'll only get an e-mail if the program outputs something to standard output (and likely standard error). A simple echo program should cause an e-mail to be sent.
Kaleb Pederson
+2  A: 

If you have sendmail installed, you can add the following to '/etc/aliases'

root: [email protected]

After you do that, update the aliases running this command:

sudo newaliases

Cron will automatically email you every time a job is run. No need to specify that in the crontab file.

Also, make sure you test your email capabilities (e.g. make sure you are able to send emails from the server) and lastly, create a trivial cronjob and test if you receive an email.

Do not assume!

alfredodeza
+1  A: 

In addition to setting up cron to send email, you can send the output of cron to a seperate syslog log facility by adding the following to your /etc/syslog.conf.

# Log cron stuff 
cron.*                                                  /var/log/cron.log 

This should log a message to /var/log/cron.log each time a job is run.

jschmier
I have no syslog.conf! I'm using Ubuntu 9... I'll see if I can find something thank btw!
RadiantHex
If you are using Ubuntu 9.10 (Karmic Koala), the sysklogd package has been replaced with rsyslog. According to the release notes, configurations in /etc/syslog.conf will be automatically converted to /etc/rsyslog.d/50-default. http://www.ubuntu.com/getubuntu/releasenotes/910
jschmier