Stop relying on cron environment variables you assumed were there
Cron & Task Scheduling (Cron/Systemd Timers/At)
Stop relying on cron environment variables you assumed were there
🧩 The Challenge
You write a script that works perfectly in your shell, but when cron runs it, the whole thing falls apart because your PATH variable is empty. I’ve wasted whole afternoons tracking down why a script couldn’t find a basic binary like rsync or grep.
💡 The Fix
Just explicitly define your path at the top of your crontab file. It saves you from having to use absolute paths for every single binary in your automation scripts.
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
* * * * * /path/to/your/script.sh
⚙️ Why It Works
Cron spins up a minimal shell environment that ignores your .bashrc or .profile entirely. Setting the variable directly in the crontab header ensures your job inherits a predictable environment every single time it fires.
🚀 Pro-Tip: Use `command -v` inside your scripts to verify binaries exist before trying to run them.
Linux Tips & Tricks | © ngelinux.com | 9/30/2026
