Cron is a simple system utility for linux to schedule things to happen at regular intervals. Most instructions tell you to edit the user's crontab with "crontab -e" which opens an editor. We needed a way to install cron tasks automatically when deploying. For that, you can replace /etc/crontab, or stick a file into /etc/cron.d/
Cron seems simple, but there are several things that can go wrong. They can be hard to debug, because since your command is started by the system, you can't see the output easily. Here are a few of the mistakes I've made
1. Use absolute paths to command - Cron doesn't keep track of your PATH.
* * * * * root /bin/echo "hello" # don't forget the /bin!
2. Specify a user - when editing the system cron, you have to specify which user is running the command like this:
* * * * * root /path/to/your/command
3. Write to a log file - You're going to lose all your stdout and stderr, so send them to a log.
* * * * * root /path/to/your/command >> /var/log/mycommand.txt 2>&1
4. Get the permissions right - Cron is picky about the permissions of the files in /etc/cron.d. Also, you have to use a simple name (no extension).
chmod 0644 /etc/cron.d/mycron
If all else fails, look at /var/log/cron to find out what went wrong.
