Join WhatsApp
Join Now
Join Telegram
Join Now

at vs. cron: Scheduling One-Time Tasks with the Overlooked Linux Command.

Avatar for Noman Mohammad

By Noman Mohammad

Published on:

Your rating ?

My first run-in with the cron trap

Last March I was rushing to patch a server before vacation. “No big deal,” I thought, “I’ll just slap the update into crontab for tonight and dump it later.” Fast-forward six weeks. The box started rebooting every Tuesday at 2:30 a.m. Clients screamed, my phone exploded, and I finally traced it to that “temporary” job I never shredded.

Why cron hates one-night stands

Cron is great for daily backups, hourly log cleanup, Monday reports—anything that loops forever. But stick a single-run fling in there and it clutters the file for years. Leftovers sit quietly:

  • sucking up disk space,
  • burning CPU on random Tuesdays,
  • winging sensitive commands with outdated credentials.

So treat cron like your favorite playlist—good songs on repeat. Anything else? Hand it to at.

Meet at: the disposable scheduler

One shot, zero mess. The job fires once, then at scrubs it away. Think of it as an email reminder that deletes itself after you read it.

Getting started in 30 seconds:

  1. Check the service:
    systemctl status atd
  2. If it’s off:
    sudo systemctl enable --now atd
  3. Schedule something:
    echo "reboot" | at 2:30

That’s it. No editing, no monthly sweep for stray entries.

Writing the at date the way you speak

at doesn’t ask for arcane formats. You can literally type:

  • at now + 30 minutes
  • at 3pm tomorrow
  • at next friday
  • at teatime (defaults to 4 p.m.)

Quick cheat sheet for busy nights

# run my backup once, in two hours
echo "/usr/local/bin/backup.sh" | at now + 2 hours

# patch server Dec 1 at 1:00
echo "yum update -y && reboot" | at 1:00 Dec 01

# bulk interactive job (Ctrl+D to save)
at 11:30 PM
service postgresql reload
logger "PostgreSQL reloaded via at"

Housekeeping

Forget what you scheduled? Run:

atq

Need to kill job 14:

atrm 14

Security—because root isn’t a playdate

Only users listed in /etc/at.allow get to play. No file? Then it blocks anyone inside /etc/at.deny. On my servers I lock it down to root and the automation account. Keeps the kids out of the cookie jar.

At vs. cron—the TL;DR

Use at for… Use cron for…
reboot tonight every night
single email reminder weekly reports
once-a-quarter cleanup daily log rotation

Switch your old single-shot crons today

  1. List your crontab: crontab -l
  2. If a line says 0 2 * * * command
    and you only needed it once, delete it.
  3. Replace with echo "command" | at 2:00
  4. Empty your graveyard.

Do it once and you’ll never trust cron for one-night stands again.

Leave a Comment