The quick checks came back clean. The daemon is running, the line is in the right crontab, the paths are absolute, and the 04:00 export still fails. Or it fails one night a week. Or it ran twice last Sunday and nobody can say why. This is the point where guessing costs more than measuring.
This guide is the slow, systematic version. If you haven't done the quick checks yet, the cron job not running checklist gets you through them in ten minutes, and where are cron logs stored finds the log line on your distro. Everything below assumes you've been there and now want to know exactly what cron did, and why it differs from what you did.
Jump to what you're seeing: works by hand but not under cron, reproduce the run. A failure with a number, read the exit code. Runs twice, overlaps or never finishes, locks and stuck runs. Wrong hour, or trouble only around a clock change, the DST night. Containers and Kubernetes, here. Vercel, GitHub Actions or Cloudflare, platform cron.
A method that beats guessing
Most cron debugging goes wrong the same way: change three things, wait for 04:00, see it fail again, learn nothing. The fix is a fixed order, where every step either finds the cause or rules out a whole class of them.
- 1
Prove whether cron started the job
Find the log line for the minute it was due. Debian and Ubuntu write
CRON[pid]: (deploy) CMD (...), cronie writes the same shape underCROND, and the logs guide has the path andjournalctlfilter for each system. ACMDline means cron did its job and the problem is your command. No line means the problem is the daemon, the crontab or the schedule, and you can stop reading your script. - 2
Capture what it printed and how it exited
Send the output to a file for one run instead of
/dev/null, as in step 8 of the checklist. Then get the exit code: on Debian, adding-L 15toEXTRA_OPTSin/etc/default/cronmakes cron log each job's end and every non-zero exit. Python buffers its output when it isn't writing to a terminal, so a killed job can die with an empty log; setPYTHONUNBUFFERED=1on the line while you debug. - 3
Reproduce the run the way cron starts it
Not
sudo ./export.shfrom your project folder. The same user, the same few environment variables, the same working directory, the same shell, no terminal. The reproducer below builds that command. - 4
Trace the reproduction
When the reproduction fails and the error message is useless, run it again with
-xto see every expanded line, or understraceto see every program it tried to start and every file it failed to open. Details in tracing a run. - 5
Change one thing, then wait for one real run
Fix the cause you found, then let cron run it for real. To avoid waiting until 04:00, add a temporary line two minutes ahead with the exact same command (or a dry-run flag), watch it, and delete it.
Run it the way cron runs it
"It works when I run it" means your terminal can run it. Cron gives the job a different user, a nearly empty environment, the owner's home directory, /bin/sh and no terminal, and on Debian it also rewrites any % in the line. Each of those differences can break a job on its own, and you can reproduce all of them at once with env -i.
Pick your cron, paste the crontab owner and the command exactly as it appears in the crontab, and run the result as root.
Cron run reproducer
one run, exactly as cron starts it
Leave it empty for /usr/bin:/bin, the default for cron (Vixie).
printf '%s\n' 'F).csv' | \
sudo -u deploy env -i \
HOME=/home/deploy LOGNAME=deploy \
SHELL=/bin/sh PATH=/usr/bin:/bin \
/bin/sh -c 'cd "$HOME" && cd /opt/app && ./bin/export.sh > /backups/$(date +' \
>/tmp/cron-repro.log 2>&1
echo "exit $?"; tail -n 40 /tmp/cron-repro.logCron cuts this line at the first unescaped %. It runs only cd /opt/app && ./bin/export.sh > /backups/$(date + and feeds the rest to the command as standard input. Write each one as \% in the crontab, or move the line into a script.
- Starts in
/home/deploy, the owner's home directory.getent passwd deployshows the real one. - No terminal: stdin is empty and output goes to a file, so prompts, colours and progress bars behave the way they do under cron.
- Four variables: HOME, LOGNAME, SHELL and PATH. No LANG, TERM, SSH_AUTH_SOCK or anything from .bashrc and .profile.
- Locale settings in /etc/default/locale do not reach the job, so tools that print UTF-8 can fail on encoding.
If the reproduction fails the way cron does, you've isolated it; fix it here, where you can iterate in seconds. If it succeeds, the difference is outside the environment: the job ran at a different time (another process held a lock, the database was in its backup window), on a different host, or under a different crontab than you think.
When a run is in progress right now, you don't need to reconstruct anything. pgrep -af export.sh gives you the PID, and tr '\0' '\n' < /proc/PID/environ prints the exact environment cron gave it, while ls -l /proc/PID/cwd shows the working directory.
A few things the environment hides that people rarely suspect:
- No
LANG. Tools that read the locale fall back to the plain C locale, so sorting,grepcharacter classes and anything that prints non-ASCII names can behave differently from your session. SetLANG=C.UTF-8at the top of the crontab. - No agent, no keychain.
ssh,git pullover SSH andgpgwork in your session because an agent holds the key. Under cron they prompt for a passphrase nobody sees and hang or exit 255. Give the job its own key with-iand-o BatchMode=yes. - No terminal. Tools that check
isattychange behaviour: no colours, no progress bars, and anything that asks "are you sure?" gets end-of-file and gives up.
Read the exit code before you read the script
The exit code is the cheapest evidence you have, and it often names the class of bug before you open a single file. The shell reserves the high numbers: per the Bash manual, 127 means the command wasn't found, 126 means it was found but couldn't run, and 128 + N means the process died from signal N. Everything from 1 to 125 belongs to the program.
Command not found
The shell could not find the program on cron's PATH, or a script's interpreter does not exist.
Check next
Use absolute paths (command -v node prints yours) or set PATH= at the top of the crontab.
Two habits make exit codes far more useful. Give the cases you expect their own numbers: flock -n returns 1 when the lock is taken, the same as most real failures, so pass -E 75 and a skipped run stops looking like a crash. And wrap long jobs in timeout, so a hang becomes a clean 124 instead of a process you discover three days later.
Tracing a run: set -x and strace
sh -x prints every line after expansion, so you see the actual path a variable held and which branch of an if the script took. It only traces the shell you started, though. To trace inside a bash script while keeping its normal error output separate, put this at the top and remove it when you're done:
#!/bin/bash
exec 9>>/var/log/export.trace
BASH_XTRACEFD=9
PS4='+ $(date +%T) line ${LINENO}: '
set -xWhen the script's own messages say nothing useful, go one level down. strace records system calls, and three of them answer most cron questions:
strace -f -tt -e trace=execve,chdir,openat -o /tmp/cron-strace.txt \
/bin/sh -c 'cd "$HOME" && /opt/app/bin/export.sh'
grep -E 'execve|ENOENT|EACCES' /tmp/cron-strace.txt | grep -v '\.so' | head -n 30execve lines show every program the job tried to start, with full arguments. A PATH problem shows up either as a row of execve(...) = -1 ENOENT attempts, one per PATH directory, or as no execve for that program at all followed by the shell's not found message. openat ... ENOENT points at the config file or .env the job looked for in the wrong directory, and EACCES is a permission it lacked.
For a run that is hanging right now, attach to it: sudo strace -f -p PID. Whatever call it sits in is your answer. A read on a socket is waiting for the network or a database, flock is waiting for a lock, wait4 is waiting for a child process, and a futex is waiting on another thread.
Cron's mail is a debugging channel too
Classic cron mails whatever a job prints to the crontab owner, or to MAILTO. On a server with no mail transport, that output is discarded or ends up in a local mailbox nobody reads, which is how a job can fail loudly for months in total silence. The logs guide covers what Debian, cronie and BusyBox each do with it.
Two cheap upgrades: set MAILTO to an address that reaches a person (and install a small relay such as msmtp if the box can't send mail), or set MAILTO="" and redirect output to a log file on purpose. The bad state is the default one, where nobody chose.
Locks, overlapping runs and runs that never finish
Cron doesn't know or care whether the previous run finished. A job every five minutes that sometimes takes seven ends up with two copies working the same rows, which is where duplicate emails and double-charged invoices come from. The standard guard is flock, and a ceiling with timeout:
*/5 * * * * /usr/bin/flock -n -E 75 /run/lock/export.lock /usr/bin/timeout -k 60 290 /opt/app/bin/export.sh >> /var/log/export.log 2>&1Read that line right to left. timeout sends SIGTERM at 290 seconds and SIGKILL 60 seconds later, so a hung run ends with 124 or 137 instead of living forever. flock -n refuses to start a second copy while the first holds the lock and exits 75, a code nothing else on the line uses.
The lock comes with a few traps of its own:
- The lock never seems to free. The kernel releases a
flocklock when the last process holding the file descriptor exits, so there are no stale lock files. If every run reports 75, something is still holding it, often a background process the job started that inherited the descriptor.fuser -v /run/lock/export.locknames it, andflock -ostops children from inheriting the lock. - Lock files in
/tmp. Cleaners such assystemd-tmpfilesprune old files there. Keep locks in/run/lockor the app's own directory. - Two machines, two locks.
flockonly works on one host. If the same crontab ships to every app server, every server runs the job. Keep scheduled jobs on one host, or take the lock in the database (pg_try_advisory_lockin Postgres, covered in the Postgres cron jobs guide). - Two schedulers during a migration. The old crontab and the new scheduler both fire for a week. Disable one before you test the other.
To find runs that are stuck, list them with their age in seconds: ps -eo pid,etimes,args | grep '[e]xport.sh'. Anything older than the job's interval is your overlap, and strace -p from the previous section tells you what it's waiting on.
The DST night: which jobs run twice, and which never run
Twice a year, local time skips an hour or repeats one. In spring, 02:00 to 02:59 doesn't exist in the US or Europe. In autumn, the US repeats 01:00 to 01:59 and Europe repeats 02:00 to 02:59. A cron job scheduled inside those windows meets whatever its implementation decided, and they didn't all decide the same thing (as documented in November 2026):
| Scheduler | Job in the skipped hour | Job in the repeated hour |
|---|---|---|
| Debian / Ubuntu cron | Runs soon after the jump | Runs once |
| cronie (RHEL, Fedora, Arch) | The two manuals disagree | The two manuals disagree |
| BusyBox crond (Alpine) | Doesn't run | Runs twice |
GitHub Actions with a timezone | Moves to the next valid time | Not documented |
Kubernetes CronJob with .spec.timeZone | Not documented | Not documented |
The Debian rows come from its cron(8) manual, and they apply only to jobs at a fixed time: anything with * in the minute or hour field (hourly jobs, */15) just follows the new clock. cronie's cron(8) describes the same catch-up as Debian, while its crontab(5) says times in the missing hour never match and times in the repeated hour run twice. BusyBox's behaviour follows from its source: it walks real minutes and matches each one against local time.
So don't rely on any of it. Keep jobs that must run exactly once out of the 01:00 to 03:00 local window, run the server in UTC and convert, or make the job idempotent so a second run is harmless. A job that runs at 09:00 local time all year is a scheduler feature, not a cron one: cronie's CRON_TZ, a systemd timer's timezone suffix, or a hosted scheduler with a per-schedule IANA timezone. Debian's cron doesn't do per-crontab timezones at all; TZ= in a Debian crontab changes only what the command sees.
Debian cron, cronie and BusyBox crond are different programs
Advice about "cron" online usually means Debian's, which descends from Vixie cron. RHEL, Rocky, Fedora and Arch ship cronie, and Alpine images run BusyBox's crond. They share the five-field syntax and differ almost everywhere else:
| Debian / Ubuntu cron | cronie | BusyBox crond | |
|---|---|---|---|
| Service name | cron | crond | crond, often no service in containers |
Default PATH | /usr/bin:/bin | /usr/bin:/bin:/usr/sbin:/sbin | crond's own PATH |
| Timezone per crontab | No | CRON_TZ= | No |
% in the command | Newline, rest goes to stdin | Newline, rest goes to stdin | Passed to the shell as is |
| Previous run still going | Starts another copy | Starts another copy | Skips the new run |
| Job output | Mailed; discarded with a log line if there is no MTA | Mailed; crond -s sends it to syslog instead | Mailed only when MAILTO is set |
The rows that bite most often in practice: a job copied from an Alpine container to an Ubuntu VM suddenly breaks on its date +%F, a job on Alpine silently skips runs while a slow one is still going, and a crontab file edited directly under /var/spool/cron/crontabs on BusyBox isn't picked up for up to an hour. Always edit with crontab -e.
systemd timers: the alternative with better debugging
On any systemd host you can skip cron entirely, and for jobs you debug often it's worth it. Every run is a unit with its own journal, its exit code and duration are recorded, Persistent=true catches up on a run missed while the machine was off, a run that is still going is never started twice, and OnCalendar accepts an IANA timezone (all per the systemd.timer manual).
# /etc/systemd/system/export.service
[Service]
Type=oneshot
User=deploy
WorkingDirectory=/opt/app
EnvironmentFile=/opt/app/.env
ExecStart=/opt/app/bin/export.sh
# /etc/systemd/system/export.timer
[Timer]
OnCalendar=*-*-* 04:00:00 Europe/Berlin
Persistent=true
[Install]
WantedBy=timers.targetThe debugging loop is where it shines. systemctl start export.service runs the job now with exactly the environment the timer will use, so "works by hand, fails on schedule" mostly disappears. systemctl list-timers export.timer shows the last and next run, systemctl status export.service shows the last exit code, journalctl -u export.service shows every line the job ever printed, and systemd-analyze calendar --iterations=3 '*-*-* 04:00:00 Europe/Berlin' proves the expression before you deploy it.
The trade-offs: two files per job instead of one line, no mail on failure unless you add an OnFailure= unit, and a default AccuracySec of one minute, so a run can land anywhere in that minute.
Containers and Kubernetes CronJobs
In a container, "cron isn't running" is the default: most images have no cron daemon, and a container runs one main process. The second trap is quieter. Debian's cron builds each job's environment from scratch, so the variables you passed with docker run -e or a Compose environment: block never reach the job, while BusyBox's crond passes its own environment through. If the job needs DATABASE_URL, have the entrypoint write the variables it needs to a file the job sources, or run a scheduler such as supercronic that keeps the container's environment. The Docker cron jobs guide compares the four patterns.
Kubernetes swaps the daemon for a controller, and the debugging starts with what it recorded:
kubectl describe cronjob export # schedule, suspend, last schedule time, events
kubectl get events --sort-by=.lastTimestamp | grep -i export
kubectl get jobs --sort-by=.metadata.creationTimestamp
kubectl create job export-manual --from=cronjob/export # run it now, same spec
kubectl logs job/export-manualThen check the settings that explain most surprises, per the CronJob and Job docs as of November 2026:
- Wrong hour. Without
.spec.timeZone, the schedule runs in the kube-controller-manager's local timezone.CRON_TZinside the schedule is rejected. - Ran several times. A failing Pod is retried up to
backoffLimittimes, 6 by default, with a delay of 10s, 20s, 40s and so on, capped at ten minutes. One scheduled run can be seven attempts. The docs also say a CronJob can occasionally create two Jobs or none for one time, so make the job idempotent. - Skipped. With
concurrencyPolicy: Forbid, a new run is skipped while the last one is still going. WithstartingDeadlineSecondsset, a run that couldn't start in time is skipped. After more than 100 missed schedules, the controller starts only the most recent one. - No evidence.
failedJobsHistoryLimitdefaults to 1 andsuccessfulJobsHistoryLimitto 3, so last week's failures are gone. Raise them while you debug. - Exit 137.
kubectl describe podshowsOOMKilledunder the last state when the container hit its memory limit.
Platform cron: Vercel, GitHub Actions and Cloudflare fail differently
Hosted schedulers remove the daemon and add their own failure modes. Here's what each vendor's docs say as of November 2026, and where to look.
Vercel Cron Jobs (manage cron jobs) call your production deployment only, in UTC. Delivery is best effort: a run can be missed with no log at all or delivered twice, and a failed run isn't retried. Cron requests don't follow redirects, so Next.js trailingSlash can turn every run into a silent 308; redirects and cached responses don't appear in the logs either. A 401 on every run means the Authorization header doesn't match CRON_SECRET, usually stray whitespace in the value or a variable missing from the Production environment. On Hobby, jobs run at most once a day, anywhere inside the scheduled hour. The Vercel cron limits post has the full picture.
GitHub Actions (schedule event) runs at most every five minutes, only on the default branch, and runs can be delayed under load (most often around the top of the hour) and some queued runs dropped. In public repositories, scheduled workflows are disabled after 60 days without activity. Times are UTC unless you set an IANA timezone. The GitHub Actions cron drift post measures how late runs actually land.
Cloudflare Workers Cron Triggers (cron triggers) run in UTC, and a change can take up to 15 minutes to propagate, during which runs can be missed. The dashboard's Cron Events keeps the last 100 invocations, and wrangler dev can fire the handler locally through /cdn-cgi/local/scheduled. The Cloudflare cron limits post covers the rest.
And sometimes the platform itself had a bad hour. Before you redeploy anything, check Vercel, GitHub or Cloudflare for an incident at your run's time. If there was one, trigger the missed run by hand once the platform recovers and watch the next scheduled one.
Never debug this blind again
Every section above starts with you noticing, usually because someone asked where the export went. Cron will never tell you that a job stopped. Three layers close that gap, and each catches something the others miss.
Log every run's outcome. A ten-line wrapper records the start, the exit code and the duration in the system log, so next time step 2 of the method is already done:
#!/bin/sh
# /usr/local/bin/cronwrap NAME COMMAND...
name="$1"; shift
start=$(date +%s)
logger -t "cron.$name" "start pid=$$"
"$@"
code=$?
logger -t "cron.$name" "end exit=$code duration=$(( $(date +%s) - start ))s"
if [ -n "$HEARTBEAT_URL" ]; then
[ "$code" -eq 0 ] && path="" || path="/fail?msg=exit+$code"
curl -fsS -m 10 --retry 3 "$HEARTBEAT_URL$path" >/dev/null
fi
exit "$code"Watch for the run that never happens. A log can't record a job that never started. A heartbeat can: the wrapper pings a secret URL when the job succeeds and the /fail URL with the exit code when it doesn't. Crontap expects the next ping within the period plus a grace window, and alerts you when a failure arrives or the ping is late, by email on every plan or in Slack, Discord or Telegram on paid plans. The wrapper above does it when the line sets HEARTBEAT_URL:
0 4 * * * HEARTBEAT_URL=https://ping.crontap.com/YOUR-TOKEN /usr/local/bin/cronwrap export /usr/bin/flock -n -E 75 /run/lock/export.lock /opt/app/bin/export.sh >> /var/log/export.log 2>&1Move the clock when the job is a request. If the job's real work is calling your own app, the crontab is just a fragile curl. A Crontap schedule calls the endpoint on its cron expression in the IANA timezone you pick, records the status code and duration of every run, retries 5xx responses, timeouts and network errors with exponential backoff, and alerts you once the attempts are used up. The free plan covers 2 schedules, uptime monitors or heartbeats combined, as often as hourly. The wider picture is in cron job monitoring, and the dead man's switch explainer goes deeper on choosing a period and grace.
FAQ
Cron troubleshooting: quick answers
- Why does my cron job work when I run it by hand but not in cron?
- Because cron runs it in a different world. It starts the job with almost no environment (HOME, LOGNAME, SHELL and a short PATH such as /usr/bin:/bin), in the owner's home directory, under /bin/sh, with no terminal. Reproduce that with env -i: sudo -u deploy env -i HOME=/home/deploy LOGNAME=deploy SHELL=/bin/sh PATH=/usr/bin:/bin /bin/sh -c 'cd "$HOME" && your-command' </dev/null. If it fails the same way, the cause is on your screen.
- How do I see the exact environment cron gives my job?
- Add * * * * * env > /tmp/cron-env.txt to the same crontab, wait a minute, remove it, and diff the file against env in your shell. On BusyBox crond the job inherits crond's own environment, so read that from /proc/$(pidof crond)/environ as well.
- What do exit codes 126, 127, 137 and 143 mean for a cron job?
- 127 means the shell could not find the command, almost always cron's short PATH. 126 means it found the file but could not execute it: no exec bit or a noexec mount. Codes above 128 mean the process died from a signal (128 + N): 137 is SIGKILL, often the out-of-memory killer or a container runtime, and 143 is SIGTERM from a shutdown, a stop or a timeout. 124 is your own timeout wrapper firing.
- Why did my cron job run twice, or not at all, on the night the clocks changed?
- It depends on the implementation. For changes under three hours, Debian's cron runs jobs skipped by the spring jump soon after it and does not repeat jobs in the repeated autumn hour. cronie's two manuals disagree with each other on this. BusyBox crond matches each real minute against local time, so a job in the missing hour does not run and a job in the repeated hour runs twice. The portable fix is to keep jobs out of the 01:00 to 03:00 local window, or to schedule in UTC.
- How do I stop cron runs from overlapping, and find a run that is stuck?
- Wrap the command in flock -n with a lock file, so a new run gives up while the old one holds the lock, and add -E 75 so a skipped run is distinguishable from a failure. Put a ceiling on it with timeout -k. To find a stuck run, list it with ps -o pid,etimes,args, see what it is waiting on with strace -p PID, and see who holds the lock with fuser.
- Should I use systemd timers instead of cron?
- On a systemd host they fix several cron pains: every run lands in the journal under its own unit, systemctl list-timers shows the last and next run, Persistent=true catches up after downtime, a service that is still running is not started a second time, and OnCalendar accepts an IANA timezone. The cost is two unit files per job instead of one line, and a default AccuracySec of one minute.
- Why is my Kubernetes CronJob not running?
- Start with kubectl describe cronjob and the namespace events. Common causes: the schedule is evaluated in the controller's timezone unless you set .spec.timeZone, suspend is true, concurrencyPolicy Forbid skipped a run because the last one was still going, startingDeadlineSeconds passed, or more than 100 missed schedules made the controller start only the latest one. Failed Jobs also disappear quickly because failedJobsHistoryLimit defaults to 1.
- How do I get alerted when a cron job fails or never runs?
- Cover both kinds of failure. Log each run's exit code and duration with a small wrapper, and give the job a heartbeat: it pings a URL on success and the /fail URL on error, and Crontap alerts you (email on every plan, Slack, Discord or Telegram on paid plans) when a failure arrives or a ping is late past its grace window. If the job is an HTTP endpoint, a Crontap schedule can call it instead, retry 5xx responses and timeouts, and alert you once the attempts run out.
Related on Crontap
- Cron job not running: the 8-step checklist. The fast triage, when you haven't ruled out the basics yet.
- Where are cron logs stored. The log path and filter for every distro, container and macOS.
- What is a cron job in Linux?. The daemon, the crontab and the syntax from the ground up.
- Cron syntax cheat sheet and the cron expression debugger. When the problem turns out to be the expression.
- Healthchecks.io paired with a scheduler. The independent dead-man pattern, if you want the watcher on a different vendor.
Language and platform guides
When the failure looks specific to your stack, the matching guide has its traps:
- Python cron jobs: virtualenvs,
manage.pyand APScheduler. - Django cron jobs: management commands, django-q2 and Celery Beat.
- Laravel cron jobs:
schedule:run, Forge and Vapor. - PHP cron jobs: the CLI vs FPM
php.initrap. - Node.js cron jobs: nvm paths, node-cron and the clustering trap.
- Postgres cron jobs and Supabase cron jobs: pg_cron and advisory locks.
- cPanel cron jobs: shared-hosting limits.
- Docker cron jobs: four container patterns.
