Force cron to pick up your actual environment variables
Cron & Task Scheduling (Cron/Systemd Timers/At)
Force cron to pick up your actual environment variables
🧩 The Challenge
Ever spent hours trying to figure out why a script works perfectly in your shell but fails immediately when it runs under cron? It’s almost always because cron runs with a stripped-down environment that doesn’t have your path or locale settings.
💡 The Fix
Don’t mess with complex environment files; just force your script to load your specific profile or explicitly declare the necessary environment right inside your crontab. It saves you from those cryptic file not found errors that plague automated jobs.
* * * * * . /home/youruser/.profile; /usr/local/bin/your-script.sh
⚙️ Why It Works
Adding that dot slash source call at the start of your crontab line essentially tells cron to spin up a login shell context before firing off your actual logic. By doing this, you ensure the script sees exactly what you see when you’re logged into your terminal.
🚀 Pro-Tip: Use absolute paths for every single executable in your cron jobs, even if you do the sourcing trick.
Linux Tips & Tricks | © ngelinux.com | 7/15/2026
