Blog ·
Cron Job Not Running? Common Causes and Fixes
Cron job not running? Usual causes: a short PATH, relative paths, no newline at the end of the crontab, unescaped % signs, timezone or day-of-week surprises.
Cron Expression Generator
Build, understand and validate cron expressions.
A cron job that does not run is usually a problem with the environment, the crontab file, or the schedule itself, not with cron. The most common causes are a PATH that is much shorter than your shell's, relative file paths, a missing newline at the end of the crontab, an unescaped % sign in the command, a server timezone you did not expect, and a day-of-month and day-of-week combination that matches more days than you intended.
Before you change anything, confirm the schedule. Paste your expression into the Cron Expression Generator to see the next run times. If the next run is not when you expect, fix the expression first. If the times look right, work through the checklist below.
Step 1: Confirm cron is running the job at all
Add a line that writes to a file so you can see whether cron fires. Redirect both standard output and standard error, so you see failures too:
*/5 * * * * /usr/bin/date >> /tmp/cron-test.log 2>&1
Wait for the schedule to fire, then check the file. If nothing is written, cron did not run the line. Check that the crontab is installed for the user you expect with crontab -l, and check your system's cron log for entries about that command. Where the log lives depends on the system.
If the test line works but your real job does not, the problem is in the job's environment or command. The next steps cover that.
Step 2: Fix the PATH
Cron does not load your shell profile. Your interactive shell may have a long PATH that includes directories added by nvm, pyenv, Homebrew, or a project's bin folder. Cron often starts with a much smaller PATH, sometimes just /usr/bin and /bin. A command like node or python that works in your terminal can fail with "command not found" under cron.
To reproduce cron's environment by hand, clear the environment and set a minimal PATH, then run the command with its full path:
env -i PATH=/usr/bin:/bin /home/deploy/scripts/cleanup.sh
If this fails while your normal shell works, the command is relying on PATH. There are two fixes. The first is to use the absolute path to the program. Find it from your terminal:
which node which python3
Then use that path in the crontab:
0 3 * * * /usr/bin/python3 /home/deploy/app/cleanup.py >> /home/deploy/cleanup.log 2>&1
The second fix is to set PATH at the top of the crontab, so every job inherits it:
PATH=/usr/local/bin:/usr/bin:/bin 0 3 * * * cleanup.sh >> /home/deploy/cleanup.log 2>&1
Absolute paths are the more predictable choice, because they make it clear which binary runs. Version managers like nvm and pyenv often install tools in per-user directories, so the absolute path can change when you upgrade. If you use one, call the binary by its full path inside the version manager's directory, or write a small wrapper script that activates the environment and run that instead.
Step 3: Replace relative paths with absolute paths
Cron does not run your command from the directory that holds your script. The working directory is usually the user's home directory, so anything that relies on the current directory breaks. This includes relative script paths, relative config files, and relative output paths.
# Breaks: ./backup.sh and config.yml are resolved from the home directory 0 2 * * * ./scripts/backup.sh # Works: absolute paths everywhere 0 2 * * * /home/deploy/scripts/backup.sh >> /home/deploy/logs/backup.log 2>&1
If your script reads files, the easiest fix is to change into the project directory first, so the script behaves the same as when you run it by hand:
0 2 * * * cd /home/deploy/app && /usr/bin/python3 backup.py >> /home/deploy/logs/backup.log 2>&1
Also check that the script file has execute permission, and that the user who owns the crontab can read and run it.
Step 4: Add a newline at the end of the crontab
Some cron implementations ignore the last line of a crontab if the file does not end with a newline. The line looks correct when you read it, but it never runs. This happens easily when you paste a line into an editor or generate the file with a tool that does not add a trailing newline.
Make sure the file ends with a blank line or at least a newline after the last job. If you edit the crontab with crontab -e, most editors add the newline for you. If you install the file from a script, write it with a final newline explicitly.
Step 5: Escape percent signs as \%
In a crontab, an unescaped % is special. The first % ends the command, and anything after it is passed to the command as standard input. The rest of the line is treated as input, not as part of the command. A date format like date +%Y-%m-%d is a common example of a command that silently fails.
# Broken: cron splits the line at the first % sign 0 1 * * * /bin/date +%Y-%m-%d >> /tmp/day.log # Fixed: escape each percent sign with a backslash 0 1 * * * /bin/date +\%Y-\%m-\%d >> /tmp/day.log
Escape every % in the command, including those in date formats, URLs with encoded characters, and inline scripts. If you need a literal percent sign in the output, \% is the correct form in the crontab. To check the escaping, put the command in a script file and run it from cron, since cron errors are easy to miss. Then compare the log output with what you get when you run the script by hand.
Step 6: Check the server timezone
Cron uses the server's local timezone by default. If your team thinks in US Eastern time but the server runs in UTC, a job set for 09:00 runs at 09:00 UTC, which is a different local time. Daylight saving time adds another layer. Jobs scheduled inside a skipped DST hour may not run, and jobs in a repeated hour may run twice, depending on the implementation.
Check the timezone with date and compare the result with the time you intended:
date date -u
If your cron implementation supports a CRON_TZ variable, you can set it in the crontab. Check your cron man page, because support varies. If it is not supported, schedule in the server's timezone and document that choice. For jobs that must run at a fixed UTC time, use UTC on the server.
Step 7: Understand day-of-month and day-of-week together
This is the most surprising rule in cron. If both the day-of-month field and the day-of-week field are restricted (neither is *), standard cron runs the job when either field matches. It does not run only on days that match both.
0 0 1 * 1 runs at midnight on the 1st of every month OR every Monday
If you want the 1st of the month only when it is a Monday, cron cannot express that in one line. Run the job every Monday and check the date in the crontab line, for example:
0 0 * * 1 [ "$(date +\%d)" = "01" ] && /home/deploy/scripts/report.sh
This runs at midnight every Monday, and the script runs only when the day of the month is 01. For background on the first-of-month pattern, see Cron Expression for First Day of the Month. For weekday schedules, see Cron Expression for Weekdays Only.
Step 8: Check for overlap and silent failures
A job that takes longer than its interval can overlap with the next run. If the job uses a shared file or database table, the second copy may fail or leave data inconsistent. Use a lock file, such as flock, to skip a run when the previous one is still going:
*/5 * * * * /usr/bin/flock -n /tmp/sync.lock /home/deploy/scripts/sync.sh >> /home/deploy/sync.log 2>&1
Also check the exit code. Cron does not show you a failed command in your terminal. Add a log line at the start and end of the script, and check the log after the next scheduled run.
A quick troubleshooting order
- Confirm the expression and next run times with the Cron Expression Generator.
- Reproduce the job in a minimal environment with env -i PATH=/usr/bin:/bin followed by the full path to the command, and compare the result with your normal run.
- Replace every program name with an absolute path, and every relative path with an absolute one.
- Set or check PATH at the top of the crontab.
- Escape every % as \%.
- Make sure the crontab ends with a newline.
- Redirect output to a log file with >> file 2>&1.
- Check the server timezone and any DST effect on the scheduled time.
- Review day-of-month and day-of-week rules if both are restricted.
If your schedule is for every few minutes or hours, the minute interval guide and the every 2 hours guide show the step syntax with next run times to compare against.
FAQ
Why does my cron job work when I run it by hand but not from cron?
Your shell loads a profile, sets a long PATH, and runs in your home directory or project directory. Cron runs with a minimal environment. Use absolute paths for programs and files, set PATH in the crontab, and redirect output to a log so you can see the error.
How do I know if cron is running my job?
Write output to a log file with >> /path/to/log 2>&1 at the end of the line. If the log has new entries after the scheduled time, cron ran the job, and the log will show whether it succeeded.
Does the crontab need a trailing newline?
Yes, in practice. Some cron implementations skip the last line if the file does not end with a newline. Add a newline after the final job to avoid this.
Is it safe to paste my cron command into an online tool?
Schedule expressions are safe to test in the Cron Expression Generator. Avoid pasting full commands that contain passwords, tokens, or connection strings into any online tool, including this one. Replace secrets with placeholders and read them from environment variables or a protected file instead.
Cron Expression Generator
Build, understand and validate cron expressions.