Ffile2fix
Sign in Get started

How to fix "errors in crontab file, can't install"

crontab: installing new crontab
"/tmp/crontab.Xy12ab/crontab":3: bad minute
errors in crontab file, can't install.
Do you want to retry the same edit? (y/n)

crontab validates the whole file before saving it, and at least one line does not follow cron syntax, so none of your changes were installed. The message before it gives the line number and which field is wrong.

Also appears as: "/tmp/crontab.Xy12ab/crontab":5: bad hour errors in crontab file, can't install. · "-":2: bad command errors in crontab file, can't install. · new crontab file is missing newline before EOF, can't install. · "/tmp/crontab.Xy12ab/crontab":4: bad day-of-week

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

  1. 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.
  2. 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.
  3. 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.
  4. Comment out non-job lines. Start notes with #. Environment lines must be NAME=value, such as [email protected] or PATH=/usr/bin:/bin.
  5. End with a newline. Press Enter after the last line before saving; otherwise crontab reports 'missing newline before EOF'.
  6. 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

Frequently asked questions

How do I run a job every 30 seconds?

Standard cron's smallest unit is one minute. Use two entries, one with sleep 30 before the command, or use a systemd timer or a long-running worker instead.

Does cPanel's Cron Jobs page have the same rules?

Yes. cPanel writes the same five-field format to your crontab, so values out of range or a seconds field will be rejected or never run.

Why does my job install but never run?

That is a runtime issue, not syntax: check the command's PATH, permissions and output. Note that an unescaped % in the command is treated as a newline by cron, so write it as \%.