Stop at from choking when your shell environment is half-baked
Cron & Task Scheduling (Cron/Systemd Timers/At)
Stop at from choking when your shell environment is half-baked
🧩 The Challenge
You ever tried to run a one-off command with at, only for it to fail silently because it couldn’t find your PATH or your custom environment variables? I’ve wasted hours staring at empty logs wondering why a script that runs fine in my terminal suddenly forgets who it is when queued.
💡 The Fix
You have to force the at command to capture your entire current environment before it gets shipped off to the queue. It saves you from the headache of manually redefining every export inside the task script.
at now + 5 minutes <<EOF
$(export -p)
/usr/local/bin/my_script.sh
EOF
⚙️ Why It Works
Passing the export -p output into the heredoc essentially snapshots your current session’s environment, ensuring the task sees the exact same variables you do. Without this, at inherits a bare-bones environment that usually breaks everything more complex than an echo command.
🚀 Pro-Tip: Run at -c [job_number] to peek at the generated shell script if you’re still not sure why your variables aren’t landing correctly.
Linux Tips & Tricks | © ngelinux.com | 8/4/2026
