Pro Tip: Manage Cron Like a Boss
Managing cron can be a little intimidating to the uninitiated. How do you load jobs in to cron? How do you know what’s running? How can you check on each job’s status? It’s a pity that the first tutorial result on Google for cron was written in 1999. A lot of what it recommends is outdated. For the most part, you should never have to mess with /etc/crontab. This is the system crontab, don’t touch it unless you know what you’re doing.
Easiest way to load new jobs
Create a file called .cron in your home folder. Edit the list of cron jobs in this file, then load it in to cron with the crontab command:
Note: This clears all existing jobs. Back them up first with the command below.
Easiest way to see what jobs are loaded
If you want to check what jobs are already loaded in cron, or generate a .cron file for the first time, run:
Optionally output this to the .cron file:
Easiest way to check a job’s status
With cron’s default settings on most machines, this isn’t an easy one. On Ubuntu, cron messages are logged to the /var/log/syslog file. There’s ways to set up logs for each cron job, but if you just want a simple way to make sure your nightly backups are running, check out Dead Man’s Snitch.
DMS is an awesome web app that shows the status of each of your cron jobs, and how long ago it last ran. It does cost $19/month for more than one job, but if you aren’t handy with the command line, it’s worth it to keep an eye on your cron jobs.
All you have to do is add a curl request to a unique URL after each cron job runs. Dead simple:
If you have any questions about Dead Man’s Snitch, send a tweet to @DeadMansSnitch. They are awesome. If you have questions about cron, cron jobs, or anything else, feel free to tweet me @nathancahill.
Cron is a powerful tool, and once you understand how it works, it’s easy to use. Now, go ahead and cron ALL OF THE THINGS!