Tag Archives: linux

Note on using cron

Edited:1)From @sureshdr on twitter, My cronjob generate too many entry to log, so updated both on the server and the post with >/dev/null 2>&1 at the end of the job.

First time have to produce an app, and maintaining the server all by myself. Previously can work with the sysadmin, now the guys in sinar is pretty busy with a day job.

So first thing first, the thing with virtualenv is, running it in a cron job can be a pain(it is not that bad). Well, billwatcher is using buildout, so it uses less command, buildout have pretty much an isolated environment. So it look like this, more on why I don’t direct to /dev/null:

0 0 * * * /path/to/Malaysia-Bill-Watcher/bin/python /path/to/Malaysian-Bill-Watcher/billwatcher/loader.py >/dev/null 2>&1

Second thing is, the last deployment, I didn’t add a full path to the sqlite database. This is important, so that the data is written in the right place.

Third, because this is my first time running cron(don’t ask why). I finally found the log file to cron.

less /var/log/cron

Except, my cronjob is run at midnight, and a few cronjob run already. Then I found zcat, because the older cronjob is /var/log/cron.n.bz2. n is the number.

zcat /var/log/cron.0.bz2|less

I read it, make sure it is running, I’m happy, then I realized that I kinda polluting the email on my system which I don’t read often. So comes the MAILTO directive. Thus my final cron job look this way

MAILTO=”[email protected]
0 0 * * * /path/to/Malaysia-Bill-Watcher/bin/python /path/to/Malaysian-Bill-Watcher/billwatcher/loader.py >/dev/null 2>&1

And the newbie sysadmin live happily ever after… Until something else break, and there is a new project coming soon…

p.s running billwatcher at midnight is a bad idea, might be a better idea doing it in the morning..