Back to articles
Debugging Crontab: Why Your Scheduled Job Is Not Running

Debugging Crontab: Why Your Scheduled Job Is Not Running

via Dev.to BeginnersMichael Lip

You wrote a script. It works when you run it manually. You added it to crontab. It does not run. Welcome to one of the most common and most frustrating debugging experiences in system administration. Nine times out of ten, the problem is not the cron expression. It is the environment. The environment trap When you run a command in your terminal, it inherits your shell environment: PATH, HOME, environment variables, shell configuration. When cron runs a command, it uses a minimal environment with almost nothing set. Your script works manually because it finds python3 at /usr/local/bin/python3 , which is in your PATH. Cron's default PATH is typically just /usr/bin:/bin . So cron cannot find python3 and the job fails silently. The fix: use absolute paths for everything in cron jobs. # Wrong * /5 * * * * python3 /home/user/scripts/cleanup.py # Right * /5 * * * * /usr/local/bin/python3 /home/user/scripts/cleanup.py Or set PATH explicitly in your crontab: PATH = /usr/local/bin:/usr/bin:/bin

Continue reading on Dev.to Beginners

Opens in a new tab

Read Full Article
6 views

Related Articles