Common causes
- A six-field schedule copied from Quartz, Spring or node-cron (with seconds), which standard cron does not support
- Values out of range, such as minute 60, hour 24, or day-of-week 8
- A line that is not a cron entry at all, such as a pasted command without a schedule or a stray word (bad command)
- Wrong separators: spaces inside lists (1, 15) or using slashes and ranges incorrectly
- The file does not end with a newline after the last entry
- Windows CRLF line endings in a file installed with crontab file.txt
How to fix it
- Go to the reported line. The number after the file name (:3) is the line to fix. Answer y to 'retry the same edit' to reopen the editor with your changes intact.
- Count the fields. Each job needs exactly five time fields followed by the command: minute (0-59), hour (0-23), day of month (1-31), month (1-12), day of week (0-7). Remove a leading seconds field.
- Fix ranges and lists. Use commas without spaces (1,15,30), dashes for ranges (1-5) and slashes for steps (*/10). Special strings like @daily or @reboot replace all five fields.
- Comment out non-job lines. Start notes with #. Environment lines must be NAME=value, such as [email protected] or PATH=/usr/bin:/bin.
- End with a newline. Press Enter after the last line before saving; otherwise crontab reports 'missing newline before EOF'.
- Fix line endings for file installs. If you install with crontab mycron.txt, convert it first with dos2unix mycron.txt or sed -i 's/\r$//' mycron.txt, then check with crontab -l.
crontab -e
[email protected]
PATH=/usr/local/bin:/usr/bin:/bin
# m h dom mon dow command
*/10 * * * * /usr/bin/php /home/user/app/cron.php
30 2 * * 1-5 /home/user/bin/backup.sh >> /home/user/backup.log 2>&1
@reboot /home/user/bin/start-worker.sh
How to stop it happening again
- Build schedules with a cron expression generator and keep a comment explaining each job
- Keep the crontab in version control and install it with crontab file after a syntax check
- Use LF line endings and finish the file with a blank line