Crontab fields
Here is how the fields are defined:
- minute
- hour
- day of the month
- month of the year
- day of the week
- program or command to run
An asterisk (*) in any field means run every time for this field. Ranges (X-Y) and steps (X-Y/Z) can also be defined.
User crontabs
To edit a user crontab (including root):
crontab -e
To delete a crontab:
crontab -r
System crontab
The system crontab is stored in /etc/crontab. It can be changed (as root) with a text editor.
The system crontab has one extra field before the program to run, which is the user to run the command as (usually root).
Error installing new crontab (bad minute)
I've received this cryptic error message while trying to update a crontab:
crontab: installing new crontab
"/tmp/crontab.XXXXScNhd2":3: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit?
The error message suggests a format problem with my entry, but the real error is due to DOS line endings (CR LF) in the file. Unix/Linux line endings just use CR. If a crontab is installed without using the crontab -e command, this error might appear.
You can check the line endings by running:
cat -v -e -t /var/spool/cron/username
If you see "^M$" at the end of each line, the file has DOS line endings. Each line should just end with "$".
The fix is to run the dos2unix command on the crontab to correct the line endings:
dos2unix /var/spool/cron/username