Stop cron from failing just because your shell path is missing

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

Stop cron from failing just because your shell path is missing

🧩 The Challenge

Everyone has that one backup script that runs perfectly in the terminal but dies a quiet death the second it hits crontab. It took me a solid three hours of debugging to realize cron isn’t running in my fancy user environment.

💡 The Fix

Explicitly define your environment variables at the top of your crontab file so the script doesn’t choke on missing binaries. It saves you from guessing why your PATH is empty.

SHELL=/bin/bash
PATH=/usr/local/bin:/usr/bin:/bin
* * * * * /path/to/your/script.sh

⚙️ Why It Works

Cron fires off with a stripped-down default environment that usually ignores your .bashrc or .profile tweaks. Hardcoding these variables ensures your tasks find their dependencies without relying on system defaults that might change.

🚀 Pro-Tip: Use absolute paths for every single executable in your scripts to be safe.

Linux Tips & Tricks | © ngelinux.com | 10/31/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted