December 4, 2026

Cron Job Not Running? Twelve Test Jobs, Seven Silent Failures, and How to Find Which One Is Yours

A wall timer switch beside an unlit lamp

“Works fine when run by hand” is the most common phrase in any cron troubleshooting thread. Cron runs commands in a stripped-down environment, reads its files under rules nobody remembers, and usually reports failures to a mailbox that nobody reads. To see each failure for real, twelve test jobs were set up on Ubuntu 24.04 with its standard cron daemon, some correct and some broken in one specific way each, and cron was left to run them for two minutes. Seven of them failed, every one silently. And every job that did run kept a clock five hours away from the one in the terminal.

Video: LearnwithDevOpsEngineer on YouTube

What cron’s environment really looks like

The test

One job did nothing but dump its environment: * * * * * env > /var/tmp/cr/out.env. The full result:

HOME=/root
LOGNAME=root
PATH=/usr/bin:/bin
LANG=C.UTF-8
SHELL=/bin/sh
PWD=/root

Six variables. The interactive shell the same commands were typed into had dozens, including a PATH with nine directories.

What that breaks

The crontab manual for Ubuntu 24.04 says cron sets SHELL to /bin/sh and takes LOGNAME and HOME from the crontab owner’s account. Everything else from a login session, .bashrc, .profile, virtual environments, tool paths, is absent. A script that works in a terminal and fails from cron is, nine times out of ten, a script that depended on something in that missing list.

The working directory

The env dump also showed PWD=/root, and a job running cd ~ && pwd printed /root. Cron starts jobs in the owner’s home directory, not in the folder where the script lives or where the crontab was edited. A script that opens config.ini or writes output.csv by relative name will look for them in the home directory, find nothing, and fail or scatter files there. Scripts meant for cron should either use absolute paths or begin with a cd to their own directory, for example cd "$(dirname "$0")" || exit 1.

Toolbox

Failure 1: command not found

The job

A small program called mytool lived in a custom bin directory that was on the interactive PATH. The cron line called it by name:

* * * * * mytool > /var/tmp/cr/out.mytool 2>&1

The result

/bin/sh: 1: mytool: not found

Cron’s PATH held only /usr/bin and /bin. The fix is either a full path in the cron line, /var/tmp/cr/bin/mytool, or a PATH= line at the top of the crontab, which cron then uses for every job below it. Programs in /usr/local/bin and /usr/sbin hit the same wall, which surprises people who never think of those as unusual locations.

Note the 2>&1. Without capturing standard error, this message would have gone to cron’s mail system and, on a machine without a mail server, nowhere.

Failure 2: the percent sign

The job

* * * * * echo "date is $(date +%Y-%m-%d)" > /var/tmp/cr/out.percent 2>&1

The result

No output file at all. The crontab manual explains: a % in the command, unless escaped with a backslash, is turned into a newline, and everything after the first one is sent to the command as standard input. The command cron actually ran was cut off at date +, so the line ended in the middle of a quoted string, the shell failed, and the redirection never happened. Even the 2>&1 meant to catch errors was on the far side of the cut.

The fix

* * * * * echo "date is $(date +\%Y-\%m-\%d)" > /var/tmp/cr/out.percent2 2>&1

With each % escaped, the job wrote today’s date as expected. Moving date formatting into a script avoids the issue entirely.

Assorted-color books in a lot

Failure 3: permission denied

A script without the execute bit:

/bin/sh: 1: /var/tmp/cr/noexec.sh: Permission denied

Running it by hand as bash noexec.sh works, which is why this one fools people. Cron runs the path directly. chmod +x, or calling the interpreter explicitly in the cron line, fixes it. The same message also appears when the script’s first line points to an interpreter that does not exist, or when the file has Windows line endings, so head -1 script | cat -A is worth a look if the bit is already set.

Failures 4 to 7: files in /etc/cron.d

Five files, one success

System cron jobs are often dropped into /etc/cron.d. Five files were created there, each with a single every-minute job:

File What was different Did it run?
goodjob Nothing: correct format, user field, newline Yes
bad.job A dot in the file name No
nonewline No newline after the last line No
nouser Missing the user field No
writable Permissions 666, writable by everyone No

None of the four failures produced an error anywhere visible.

Why each one failed

  • The dot. The Debian cron manual, the same cron Ubuntu ships, says file names in /etc/cron.d must consist only of letters, digits, underscores and hyphens, following the run-parts convention. bad.job was skipped, and so would backup.cron or myjob.conf.
  • The newline. The crontab manual says each entry must end in a newline character, and a last line without one can be treated as broken. Some editors and printf commands leave it off.
  • The user field. Files in /etc/cron.d and /etc/crontab need a username between the time fields and the command, according to the same manual. Without it, cron read echo as the user name and the job never ran. Personal crontabs edited with crontab -e have no user field, which is where the confusion comes from.
  • Writable permissions. The Debian manual says these files must be owned by root and must not be group- or other-writable. A world-writable file would let any user add a root job, so cron ignores it.
Wall clock

The eighth surprise: the clock is in another time zone

What the test showed

The terminal session had TZ=America/New_York set and showed the time as 01:47. The cron-run script logged the same moment as 06:47. The system’s own time zone, from /etc/localtime, was UTC, and cron used that, not the variable set in a user’s shell.

Nothing in cron’s output or the job’s own log would have revealed the difference; the timestamps were simply the ones the system clock produced. A job written as 0 2 * * * for “2 a.m. local time” on this machine runs at 2 a.m. UTC, which is evening of the previous day in New York. The Debian manual notes that cron handles tasks in a single time zone. timedatectl shows the system zone; servers are often left on UTC on purpose, in which case the cron times should be written in UTC too.

A debugging routine that works

Eight checks, in order

  1. Is cron running? systemctl status cron (the service is cron on Debian and Ubuntu, crond elsewhere).
  2. Is the crontab what it seems? crontab -l shows the personal table exactly as cron stored it, and ls -l /etc/cron.d shows names and permissions at a glance.
  3. Did cron try? grep CRON /var/log/syslog or journalctl -u cron shows each launch. No entry means a scheduling or file problem; an entry means the command itself failed.
  4. Capture the output. Append >> /tmp/job.log 2>&1 to the line, wait a minute, and read the file.
  5. Reproduce cron’s environment. env -i HOME=$HOME LOGNAME=$USER PATH=/usr/bin:/bin SHELL=/bin/sh /bin/sh -c 'the command' runs a command the way cron will, which usually reproduces the failure on the first try.
  6. Look for %. Escape every one, or move the command into a script.
  7. For /etc/cron.d: a name without dots, a user field, a final newline, owned by root with mode 644.
  8. Check the time zone against what the schedule assumes.

Making jobs easier to trust

Full paths, a PATH= line at the top of the crontab, output redirected to a log, and scripts that set their own environment remove almost every failure above.

One more failure looks like “not running” but is the opposite: a job that runs every few minutes and sometimes takes longer than that, so copies pile up and fight over the same files. Wrapping the command in flock prevents it:

*/5 * * * * flock -n /tmp/backup.lock /usr/local/bin/backup.sh >> /var/log/backup.log 2>&1

In a quick test, a second flock -n on the same lock file, started while the first was still running, exited immediately with status 1 and did nothing, while the first finished normally. The overlapping run is skipped instead of colliding. For jobs that matter, systemd timers log every run to the journal automatically, which is the subject of an earlier article in this series.

Seven of twelve jobs failed in this test, and not one of them complained. Cron’s silence is not a sign that a job ran. It is a sign that nobody was listening.

Sources

  • crontab(5), Ubuntu 24.04 manual page: https://manpages.ubuntu.com/manpages/noble/man5/crontab.5.html
  • cron(8), Debian bookworm manual page: https://manpages.debian.org/bookworm/cron/cron.8.en.html

719 Posts

Peter Kalafatis writes and edits X9M8. He holds a bachelor's degree from LIU Post and a master's in Media Studies from The New School, with academic work in the philosophy of science, human behavior, AI, and memetics.

View All Posts

Leave a Reply

Your email address will not be published. Required fields are marked *