21

I have a python script running by cron. For what ever reason, it is not running. I am wondering if there is anywhere that error messages are sent? Script runs fine by itself. If I run a simple script with crontab, that just writes to a file that works also.

My crontab is:

*/15 * * * * python ./home/pi/foo/bar.pyw
Richard
  • 471
  • 2
  • 5
  • 9
  • 1
    Ok, I figured out the issue with my script. I was calling modules which were in the same directory as the bar.pyw script. I changed the working directory with os.chdir("some location"). I still however would like to know where the error messages go for crontabs – Richard Nov 26 '12 at 19:46

2 Answers2

27

By default, the logging for the cron daemon is not enabled in Debian (I assume it is the system you are using). To enable it, please open the file /etc/rsyslog.conf via

$ vi /etc/rsyslog.conf

and uncomment the line

# cron.*                          /var/log/cron.log

After that, you need to restart rsyslog via

$ /etc/init.d/rsyslog restart

and you will find the cron logs in /var/log/cron.log

Source: Enable crontab logging in Debian Linux

Kioshiki
  • 103
  • 3
Morgan Courbet
  • 3,703
  • 3
  • 22
  • 38
  • 1
    Alf: Thank you for your reply. I have now implemented cron logging and have alter the command in my crontab to [Code] /3 * * * /usr/bin/sudo -H /home/pi/ahbc [/code] The sudo -H is something I found on the web which I am told works. I don't understand just what the -H is there for. I have been given to understand that if one does not include the uservin a crontab command line that command will run using the user/owner of crontab. Therefore as my crontab is user pi crontab the contained commands will run for pi. – Bex Jan 12 '15 at 07:42
  • the link is broken now :( – Michael Jun 08 '15 at 20:27
  • @Michael The explanation here should be enough to achieve logging. Do you need something else? – Morgan Courbet Jun 08 '15 at 21:43
  • 2
    @ElanHasson Anything that generates extra writes to the SD card and is a low priority is generally disabled on the rPi. – SiKing Dec 02 '16 at 16:39
  • I've just posted an edit request for the link, it looks like the source site just changed it's setup a bit. – Kioshiki Jan 22 '17 at 14:53
  • If you want to monitor it is real time, use tail -f /syslog – SDsolar Jun 02 '17 at 06:27
4

Crontab has several parameters (in additional to time execution lines) For example:

MAILTO="you@example.com"
SHELL="/bin/bash"
goldilocks
  • 58,859
  • 17
  • 112
  • 227
DGerman
  • 41
  • 1