Showing posts with label cron. Show all posts
Showing posts with label cron. Show all posts

Thursday, November 20, 2014

cron debugging: cat /var/log/syslog

So I wanted to test a cron job and make sure that it was running.  I decided to make it something obvious, so I made my command

/usr/bin/firefox www.google.com

and told it to run every minute.  And I got nothing.  After restarting cron and making sure that the last line in crontab had a newline and everything I could think of, I finally looked at the syslog and learned that it was running.  It just didn't output anywhere I could see it.

So here's another case where it's worth looking at syslog:

cat /var/log/syslog

The cron output isn't visible unless you direct it to a file that you choose and look at that file.

adding commands to manage.py (if you don't like the shell < script.py trick)

Say you want to do something periodically that will affect your django environment (like check email).  You can schedule a task to do that using cron.  But that task needs to be run within your django environment.

One way to do that is to use

python manage.py shell < script.py

(or, if you have your permissions altered via chmod +x, 

./manage.py shell < script.py

)

It works.

If you want to get fancier, you can make a custom command for manage.py:

https://docs.djangoproject.com/en/dev/howto/custom-management-commands/