30 Days of Tech: Day 8 - Cron Woes
June 8th, 2008
Yesterday I wrote about a Ruby script I set up to be run by cron that would make sure pages cached by Mephisto were cleared for future-dated articles that I publish. After I wrote the script and added the cron entries for it…
Yesterday I wrote about a Ruby script I set up to be run by cron that would make sure pages cached by Mephisto were cleared for future-dated articles that I publish. After I wrote the script and added the cron entries for it, I encountered some cron problems I had never seen before.
The first thing I noticed was that the script simply wasn’t being run. I knew it wasn’t being run because the script includes this line
LOGGER.info "\n\n============== Running at #{Time.now.utc} UTC"
and nothing was showing up in the log file. Seeing as I didn’t think cron was broken, I wondered what could have gone wrong. I checked both root’s mailbox and the mailbox of the user whose crontab I added the script to, but there were no emails from cron saying the script encountered an error. Clearly strange things were afoot at the Circle K.
After staring an the crontab entry for awhile and convincing myself it was right, it occurred to me that cron must have a system logfile that would probably be helpful. I found it in /var/log/cron, and opened it up to find this:
Jun 7 18:05:01 davidvollbracht crond[2208]: (CRON) chdir(HOME) failed: (No such file or directory)
Jun 7 18:05:01 davidvollbracht crond[2208]: CRON ([USERNAME REDACTED]) ERROR: cannot set security context
Sure enough, the user whose crontab I had edited didn’t have a home directory! I did a quick mkdir and suddenly the whole solution started working as cron could now run the script.
All in all it wasn’t too bad to troubleshoot the problem, but I have one big gripe here. The crontab command let me edit the crontab entries for a user that would never work because the user didn’t have a home directory. Crontab could have saved me a lot of time by at least printing a warning message that I needed to create a home directory for the entries to have a chance at running. In the end, though, at least there was a log file and it contained useful information the moment I opened it, so I’m thankful for that. In the future, though, always remember to double check that a user has a home directory before adding cron entries for them!
Sorry, comments are closed for this article.