Stop cron from silent-killing your scripts when the environment is bare

Cron & Task Scheduling (Cron/Systemd Timers/At)

Stop cron from silent-killing your scripts when the environment is bare

🧩 The Challenge

Everyone has had that moment where a script works perfectly in your terminal but fails silently when triggered by cron. It turns out cron runs with a pathetic, minimal path and environment, so half your commands don’t even exist when it tries to run them.

💡 The Fix

Start your crontab with a custom PATH definition that matches what your shell actually sees. This saves you from having to use absolute paths for every single binary you call.

PATH=/usr/local/bin:/usr/bin:/bin
* * * * * /home/user/scripts/backup.sh

⚙️ Why It Works

Setting these variables at the top of the file tells the cron daemon exactly where to look for your tools. Without these overrides, it defaults to /usr/bin:/bin, which usually misses everything useful installed in /usr/local/bin.

🚀 Pro-Tip: Always pipe your cron output to a log file using >> /var/log/myjob.log 2>&1, otherwise the errors go to the local mail spool and sit there rotting forever.

Linux Tips & Tricks | © ngelinux.com | 8/7/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted