Scheduling one-off tasks with 'at'

You might be familiar with the cron job scheduler, which is great for repeating tasks. But when you want to schedule a command to only run once in the future, the at command is what you are looking for.

In my case, I was updating a plugin for our Thoughtworks Mingle instance, but the update wasn’t hugely important. Many of our staff rely on Mingle for their work, and restarting it takes it offline for a few minutes.

So I used the at command to schedule the restart to happen at midnight, after everyone had gone home:

$ echo "/etc/init.d/mingle restart" | at -m 00:00
job 6 at 2012-02-26 00:00

Use atq or at -l to see the list of pending jobs:

$ atq
6 2012-02-26 00:00 a root

Use at -c <job id> to view the script that will be run:

$ at -c 6


# atrun uid=0 gid=0

# mail root 1

umask 22
<lots of environment variables set here>

/etc/init.d/mingle restart

To delete a scheduled task, run at -d <job id>:

$ at -d 6
$ atq
(no output)
comments powered by Disqus