...an active Linux User Group at Kuching, Sarawak, Malaysia.


Tuesday, March 28, 2006

About cron and the annoying "/bin/bash: root: command not found" error

Recently I was plagued by a series of emails generated by cron, sent to my root user account, claiming it can't find the command "root" in my crontab. After searching high and low on Google, I finally came across a posting which gave me a clue.

See, the system wide crontab (located at /etc/crontab) is the only crontab which specifies the user right running a particlar task. eg.

#tries to annoy me at 2:30am everyday
30 2 * * * root /root/annoy_me

This crontab entry specifies the annoy_me task to be run at 2:30am everyday by user root. Now, usually you'll use the command crontab -e to edit your own tasks. But if you happen to edit the /etc/crontab file manually, DO NOT run the command crontab /etc/crontab!! This will cause cron to take /etc/crontab as a user crontab and thus expecting field 6 (the field straight after the first 5 time specification fields) to be the command to execute.

So boys and gals, if that happens:

1. backup your system wide crontab file (/etc/crontab)
2. run crontab -r as root, to flush all the cron jobs
3. check if the system wide crontab is still in good health, if it is leave it be
4. restore the system wide crontab file if necessary
5. cron will read and execute the system wide cron tasks accordingly next time it wakes up

This is my understanding as far as explaining what happened to my FC4 cron installation. Comments and corrections welcome.

Cheers
Hong