Cron job not running? Causes and fixes, from PATH to permissions

Your cron job works when you run it by hand but not on schedule. How to tell whether cron ran it at all, and how to fix the usual culprits: environment, syntax, permissions, time zones, containers and GitHub Actions.

· 7 min read · By the Spot Downtime team

The script runs perfectly when you type it into a terminal. You add it to the crontab, wait for the scheduled time, and nothing happens. No output, no error, no email. This is one of the most common problems on Linux servers, and almost always one of a dozen known causes.

The fastest way through is to answer one question first: did cron start the job at all? If it didn't, the problem is the schedule, the crontab or the cron daemon. If it did, the job started and then failed, usually because cron's environment isn't your shell's.

Step 1: check whether cron ran it

Cron logs every job it starts. Where the log lives depends on the distribution:

bash
# Debian and Ubuntu
grep CRON /var/log/syslog | tail -20
journalctl -u cron --since "1 hour ago"

# RHEL, Rocky, Alma, Fedora, Amazon Linux
tail -20 /var/log/cron
journalctl -u crond --since "1 hour ago"

A line like (deploy) CMD (/opt/backup.sh) at the expected minute means cron did its part: skip to step 3. No line at all means cron never tried: keep reading.

Tip

Lines saying No MTA installed, discarding output are a strong hint. The job ran and printed something, probably an error, and cron had nowhere to send it.

Step 2: cron didn't start the job

1. The cron daemon isn't running

Minimal servers and most containers don't run cron by default.

bash
systemctl status cron     # Debian/Ubuntu
systemctl status crond    # RHEL family
sudo systemctl enable --now cron

2. The schedule doesn't mean what you think

Cron's five fields are minute, hour, day of month, month and day of week. A few rules catch everyone eventually:

  • 0 */2 * * * runs every two hours on the hour. * */2 * * * runs every minute of every other hour.
  • When both day of month and day of week are set, cron runs when either matches. 0 9 1 * 1 runs on the 1st and on every Monday, not only on Mondays that fall on the 1st.
  • Day of week 0 and 7 are both Sunday.
Cron expression explainerPaste a schedule to see it in plain English, with the next run times, before you wait a day to find out.

3. The wrong number of fields

A user crontab (crontab -e) has five time fields and then the command. The system files /etc/crontab and /etc/cron.d/* have a sixth field, the user to run as. Copy a line from one to the other and cron reads your command's first word as a user name, or the user name as a command.

crontab
# crontab -e (no user field)
0 2 * * * /opt/backup.sh

# /etc/cron.d/backup (user field after the schedule)
0 2 * * * root /opt/backup.sh

4. A file in /etc/cron.d is silently ignored

On Debian and Ubuntu, file names in /etc/cron.d may only contain letters, digits, underscores and hyphens. A file called backup.cron or app.conf is skipped without a word. The file must also be owned by root and not writable by group or others.

5. The last line has no newline

Cron needs every entry, including the last, to end with a newline. Some editors don't add one, and cron then ignores the final line (sometimes logging premature EOF). Add an empty line at the end of the file.

6. An unescaped percent sign

In a crontab, % means “newline”, and everything after the first one is passed to the command as standard input. This breaks the classic dated backup:

crontab
# Broken: cron cuts the command at the first %
0 2 * * * tar czf /backups/site-$(date +%F).tgz /var/www

# Fixed
0 2 * * * tar czf /backups/site-$(date +\%F).tgz /var/www

Simpler still: move the command into a script and call the script from cron.

7. You're not allowed to use cron

If /etc/cron.allow exists, only the users listed in it can have crontabs. If only /etc/cron.deny exists, everyone except the users listed can. crontab -e tells you when you're refused, but jobs added some other way just never run.

8. The crontab was edited directly

Files under /var/spool/cron are cron's own storage. Editing them by hand may not be picked up. Always use crontab -e, or crontab file.txt to install a file, and check the result with crontab -l. Also make sure you edited the right user's crontab: sudo crontab -e edits root's, not yours.

9. The time zone isn't yours

Cron uses the server's system time zone, and cloud servers are usually set to UTC. A job meant for 9:00 in New York runs at 9:00 UTC, which is 4 or 5 in the morning there. Check with timedatectl. Daylight saving changes can also skip or repeat jobs scheduled between 1:00 and 3:00 local time.

10. The machine was off

Cron doesn't catch up. If a laptop or a stopped VM is off at 2:00, the 2:00 job simply doesn't happen. For jobs that must run once a day whenever the machine is up, use anacron or a systemd timer with Persistent=true.

Step 3: cron ran it, but it failed

Cron starts jobs with an almost empty environment: /bin/sh rather than bash, a PATH of about /usr/bin:/bin, the home directory as the working directory, and none of the variables from your .bashrc or .profile. Most “works by hand, fails in cron” problems come from that.

Capture the output first

Until you can see the error, you're guessing. Send the job's output to a file:

crontab
0 2 * * * /opt/backup.sh >> /var/log/backup.log 2>&1

Command not found

Tools installed in /usr/local/bin, ~/.local/bin, by nvm, pyenv or rbenv aren't on cron's PATH. Use full paths (find them with which node), or set PATH at the top of the crontab:

crontab
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
0 2 * * * /opt/backup.sh

Bash syntax under sh

Commands written directly in the crontab run under /bin/sh, which on Debian and Ubuntu is dash. source, [[ ]], arrays and {a,b} expansion fail there. Put a #!/bin/bash line at the top of your script, or set SHELL=/bin/bash in the crontab.

Missing environment variables

Database URLs and API keys you exported in your shell profile don't exist in cron. Load them explicitly from a file the job can read, inside the script:

bash
#!/bin/bash
set -euo pipefail
set -a; . /opt/app/.env; set +a
cd /opt/app
./bin/nightly-report

Relative paths

Cron starts the job in the user's home directory, so ./data/export.csv points somewhere else. cd into the right directory first, or use absolute paths throughout.

Permissions and line endings

  • The script must be executable: chmod +x /opt/backup.sh. A Permission denied in the log means it isn't, or that the cron user can't read a file the script needs.
  • A script saved on Windows has CRLF line endings and fails with /bin/bash^M: bad interpreter. Convert it with dos2unix or sed -i 's/\r$//'.

Reproduce cron's environment

Instead of waiting for the next run, start the script the way cron would:

bash
env -i HOME="$HOME" LOGNAME="$USER" SHELL=/bin/sh PATH=/usr/bin:/bin \
  /bin/sh -c '/opt/backup.sh'

If it fails here, it fails in cron, and now you can see why.

Overlapping runs

A job scheduled every 5 minutes that sometimes takes 7 piles up copies that fight over the same files or locks. Wrap it in flock so a new run is skipped while the last one is still going:

crontab
*/5 * * * * flock -n /tmp/sync.lock /opt/sync.sh

Containers, Kubernetes and GitHub Actions

Docker

A container runs one process, and it usually isn't cron. A crontab copied into an image does nothing unless the container actually starts the cron daemon in the foreground. Even then, cron doesn't pass the container's environment variables to jobs. Running the schedule outside the container (the host's cron, a Kubernetes CronJob or your platform's scheduler) is usually simpler.

Kubernetes CronJobs

  • Check kubectl get cronjob: SUSPEND must be False, and LAST SCHEDULE shows when it last fired.
  • Schedules are in the controller's time zone, normally UTC, unless you set spec.timeZone.
  • With concurrencyPolicy: Forbid, a stuck job blocks every later run. If the controller misses more than 100 schedules, it stops scheduling the job until you set startingDeadlineSeconds.

GitHub Actions

  • Scheduled workflows only run from the default branch.
  • In public repositories, they're disabled after 60 days without repository activity.
  • Runs are often delayed at busy times, especially at the top of the hour. Schedule at an odd minute like 17 * * * *.

A quick checklist

  1. Is there a log line for the run? If not, check the daemon, the schedule, the field count and the file name.
  2. Is the output captured somewhere? Add >> file 2>&1.
  3. Does it use full paths, the right shell and its own environment variables?
  4. Does it work under env -i?
  5. Is the time zone the one you meant?

Find out next time without checking

Everything above starts with you noticing that the job didn't run, often days later. A heartbeat monitor turns that around: the job calls a unique URL when it finishes, and you're alerted when the call doesn't arrive on time. A job that never started, crashed, hung or was lost in a server move all look the same: silence.

crontab
0 2 * * * /opt/backup.sh && curl -fsS -m 10 --retry 3 https://spotdowntime.com/api/v1/ping/YOUR_TOKEN

Our guide to monitoring cron jobs with heartbeats covers the setup for crontab, scripts, GitHub Actions and Kubernetes, and how to choose a grace period. Heartbeat monitors are included from the Starter plan: see how they work.

Get new guides by email

Practical posts on monitoring, outages, error fixes and on-call, when they're published. No spam.

Unsubscribe from any email with one click. See our privacy policy.

Keep reading