Saturday, February 16, 2013

Testing Cron on Linux (RedHat, Ubuntu. ...) - thanks to Stack Overflow

Nice diagnostic technique I used when the behavior of cron (for automated regressions) on our RedHat servers was suspect:
...
"
Ok, let's start over again.
Create a file, say cron.txt, with exactly the following contents (1 line):
* * * * * touch $HOME/CRON_IS_RUNNING
(Do not create CRON_IS_RUNNING manually.) Run
crontab cron.txt
which should quietly produce no output, then
crontab -l
which should print
* * * * * touch $HOME/CRON_IS_RUNNING
Wait a minute or so, perhaps 2 minutes, then
ls -l $HOME/CRON_IS_RUNNING
which should print something like
-rw-r--r-- 1 yourname yourgroup 0 2011-08-23 20:11 CRON_IS_RUNNING
If this all works, it will confirm that you can run cron jobs.
If that's successful, the problem may be with your test.py command. Does it work when you run it from the command line? If it works from the command line but not from crontest.py might have some dependency on environment variables (cron jobs run with fewer environment variables set than interactive commands typically do).
"
...
Testing Crontab on Debian Ubuntu - Stack Overflow

'via Blog this'

No comments:

Post a Comment