Stop cron from nuking your PATH and breaking your scripts
Cron & Task Scheduling (Cron/Systemd Timers/At)
Stop cron from nuking your PATH and breaking your scripts
🧩 The Challenge
Ever had a script work perfectly in your shell but fail completely when triggered by cron? You spend an hour debugging the logic only to realize the cron environment doesn’t know where /usr/local/bin lives.
💡 The Fix
Explicitly define your shell environment variables at the top of your crontab file to mirror your login session. It saves you from those cryptic “command not found” errors that only happen at 3 AM.
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
SHELL=/bin/bash
* * * * * /path/to/your/script.sh
⚙️ Why It Works
Cron runs with a barebones, minimal path by default, which is why it often misses those custom binaries you installed. Defining these variables at the top of the file forces the scheduler to look in the right places for your tools.
🚀 Pro-Tip: Always use full absolute paths for every single executable inside your script; never rely on the PATH environment variable for anything critical.
Linux Tips & Tricks | © ngelinux.com | 8/15/2026
