Basics for Setting Up Crontab

For editing cron jobs on a server. Steps to edit and explanation of what each thing means.

Steps in PuTTY to access and edit

Step 1. Login to the server.

Step 2. Type crontab -e to open crontab. Scroll down (may need to use arrow keys) to view current commands list.

Step 3. Press Insert to make cron jobs editable.

Step 4. Edit file, then press Esc to stop editing.

Step 5. Type :wq to exit the crontab. You’ll need to do this to get the message "installing new crontab"

Basic Cron Setup

Cron allows a great deal of specificity in how things are set up:

MIN — Minute 0-60  
HOUR — Hour [24-hour clock] 0-23  
MDAY — Day of Month 1-31  
MON — Month 1-12 OR jan,feb,mar,apr...
DOW — Day Of Week 0-6 OR sun,mon,tue,wed,thu,fri,sat  
COMMAND — Command to be run Any valid command-line  

The command above will run every 10 minutes. The / runs it against any minute * to see if it’s divisible by 10. Without the asterisk and slash, it would run on the 10th minute of every hour.

Commas and dashes should be used to designate multiple items in any section. For example:

01,31 04,22 1-15 1,6 * /usr/bin/somedirectory/somecommand

…would run on the 1st and 31st minutes of 4am and 10pm on the Jan 1-15 and June 1-15. That’s an unlikely use case but I wanted to demonstrate how commas work.

30 0 * * sun,wed /usr/bin/somedirectory/somecommand

…would run at 12:30am (0030 hours) each Sunday and Wednesday.

For more detailed information about Cron, see the Ubuntu Cron Reference Guide.