- One line per command
- Comments begin with "#"
- whitespace between fields is insignificant
- Fields
- minute
- hour
- day
- month
- weekday
- command
- Recommendation:
- Start your crontab file with the line
#minute hour day month weekday command
- Line up the columns in your entries to make the fields fit under their name
- It beats trying to re-remember (or look up) the order of the fields each time you edit the file
- Time fields
- ranges
- minute: 0-59
- hour: 0-23
- day of month: 1-31
- month: 1-12
- day of week: 0-6
- specification
-
- single integer
- comma-separated integers (e.g. 1,11,35)
- matches any number in the list
- hyphen-separated integers (e.g. 1-5)
- matches any number in the range
- One "gotcha"
- The "day of week" field is "OR"ed with the other date fields, not "AND"ed.
- So the specification 30 4 13 * 5 happens at 4:30 am on the 13th of every month and at 4:30 am every Friday
- Not at 4:30 am on every Friday the 13th
- If that's what you want, you'll need to write a shell script, run it every 13th, and have the script check to see if it's Friday
- Command field
- Any valid sh command line
- Most versions allow "%" as a replacement for a newline
- First line is command, following lines provide stdin for the command (I've never used this feature, so I'm not sure what you'd use it for)
- Caution: Your comands will run with the Bourne Shell, and with none of your environment
- If you need an environment variable, you'd better define it
- You can't use things like '~' on the command line, because that's a feature of just about every shell but the Bourne Shell
- You can, however, run a csh or ksh script if there are certain features you need
- Some examples
- 59 23 * * * /users/geoff/bin/mail-summary
- Every day, at 23:59, run the mail-summary command (which supposedly does some sort of mail summary! ;^) )
- 30 16 * * 1-5 echo "Time to go home" | mailx -s "Get a life!" joebob
- Every weekday, at 4:30 pm, send email to joebob telling him to go home
- 23 22 9,24 * * /usr/local/bin/print-paychecks
- On the 9th and 24th of every month, at 10:23 pm, print the employee paychecks
- The textbook has a few other examples