Lesson 09 · tested on Debian 13
Cron job not running? It works in the terminal, here's why it fails in cron
A script runs fine when you type it, but does nothing from cron. Using a real cron daemon, this video logs the job's output to see the actual error, dumps cron's environment to show its tiny PATH and different working directory, fixes both in the crontab, and explains the percent-sign trap that silently breaks date commands in cron.
Video coming soon — @ShellProven
Commands
Exactly as run in the video. Full folder with setup script and log: terminal-tutorials/cron-not-running.
# A script that works
$ cat backup.sh
#!/bin/sh
report-tool > report.txt
echo "saved report"
$ ./backup.sh && cat report.txt
saved report
report for demo: 42 orders
# Schedule it, and log the output
$ cat first.cron
# min hour day month weekday command
* * * * * /lab/jobs/backup.sh >> /tmp/backup.log 2>&1
* * * * * env > /tmp/cron-env.txt
$ crontab first.cron && crontab -l
# min hour day month weekday command
* * * * * /lab/jobs/backup.sh >> /tmp/backup.log 2>&1
* * * * * env > /tmp/cron-env.txt
# Why it fails
$ cat /tmp/backup.log
/lab/jobs/backup.sh: 2: report-tool: not found
saved report
$ cat /tmp/cron-env.txt
HOME=/root
LOGNAME=root
PATH=/usr/bin:/bin
SHELL=/bin/sh
PWD=/root
$ ls /root
report.txt
# The fix: PATH and cd in the crontab
$ cat fixed.cron
PATH=/usr/local/bin:/usr/bin:/bin
# min hour day month weekday command
* * * * * cd /lab/jobs && ./backup.sh >> /tmp/backup.log 2>&1
* * * * * echo "ran at $(date +%H:%M)" >> /tmp/broken.log
* * * * * echo "ran at $(date +\%H:\%M)" >> /tmp/fixed.log
$ crontab fixed.cron
# Check it
$ tail -n 1 /tmp/backup.log && cat report.txt
saved report
report for demo: 42 orders
# The percent-sign trap
$ cat /tmp/broken.log
cat: /tmp/broken.log: No such file or directory
$ cat /tmp/fixed.log
ran at 20:08
Quick check
Same two questions as in the video. Checked here, in your browser — nothing is sent anywhere.
Transparency. Script and narration made with AI, human-reviewed. The robot and the dog are AI-generated cartoon characters. The commands and their output are real runs in a container.