Stop cron from losing your mind when env variables go missing
Cron & Task Scheduling (Cron/Systemd Timers/At)
Stop cron from losing your mind when env variables go missing
🧩 The Challenge
Spend half a day wondering why your backup script works fine in your terminal but throws absolute tantrums when cron runs it. It usually comes down to your PATH variable being basically non-existent in a cron environment.
💡 The Fix
Don’t guess which directories your script needs to find executables. Just declare the environment variables explicitly at the top of your crontab so your tasks stop failing for no reason.
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 bare-bones shell environment by default, which means it doesn’t inherit your carefully crafted bashrc or profile settings. Setting these variables inside the crontab file itself forces the runner to use the path you expect.
🚀 Pro-Tip: Always use full absolute paths for every single binary in your scripts, because relying on PATH in cron is just asking for a midnight wake-up call.
Linux Tips & Tricks | © ngelinux.com | 8/3/2026
