Stop mucking with crontabs for one-off tasks
Cron & Task Scheduling (Cron/Systemd Timers/At)
Stop mucking with crontabs for one-off tasks
🧩 The Challenge
Ever had a server reboot scheduled for 3 AM and needed to run a specific database sanity check script *just once* after it came back up? Or maybe a package upgrade means a service needs to restart in exactly 15 minutes. Nobody wants to drop a temporary line in their crontab and then forget to clean it up, only to have it fire unexpectedly weeks later. That’s a mess.
💡 The Fix
Forget messing with crontabs for this. There’s a much cleaner way to schedule a command to run exactly one time, then vanish. Use the `at` command. It’s perfect for these fire-and-forget situations.
# Run a single command in 15 minutes
at now + 15 minutes <<< "systemctl restart myapp.service"
# Schedule a script to run tomorrow morning at 3:30 AM
at 03:30 AM tomorrow <<< "sudo /opt/scripts/post_reboot_db_check.sh"
# Schedule a more complex script from a file for an hour from now
at now + 1 hour -f /var/tmp/complex_migration_script.sh
⚙️ Why It Works
The `atd` daemon keeps tabs on these jobs, patiently waiting. When the specified time rolls around, it executes your command or script in a new shell. Once it’s run, the job’s gone from the queue, so no lingering cruft or unexpected surprises later.
🚀 Pro-Tip: Type `atq` to list your queued jobs and `atrm JOB_ID` to remove one if you change your mind.
Linux Tips & Tricks | © ngelinux.com | 10/27/2026
