Trigger and Organize Timed Tasks with ‘at’

Since I am doing more and more stuff on the commandline, I noticed that sometimes I just wait for some task to finish to do a next step in a sequence to accomplish a certain goal. What if a running task would take an estimated 3-8 hours and it is Friday afternoon?

In this case you can use the commandline-tool ‘at’ and schedule something like ‘at 1am tomorrow do xyz’.

If you do not have at yet, install it on your Debian box with: apt-get install at

There are 3 commands available:

  • at <datetime> – Starts the scheduling-dialog for a specific date or/and time to execute certain commands.
  • atq – Shows a list of already scheduled and pending jobs.
  • atrm <job-id> – Deletes pending jobs you would like to remove from the job-queue.

Case: What do you have to do in order to set a sequence of commands as root at a specific time?

Let’s say it is Friday 15:00h (and the server-clock says that too) and you would like to fire the command

  • echo “Good morning!” > hello.txt @ 08:00h tomorrow

You would do the following:

  • Log in as root.
  • Type ‘at 8.00′ <enter>.
  • Since for today 08.00 is already in the past, at assumes that you mean tomorrow. But you can use all sorts of time- and date signatures, for example you could use ‘at 08:00 01.06.2008′.
  • Now the prompt changes to at> and waits for your commands to be executed sequentially at the time you specified.
  • Now you type your first command to be executet: ‘cd ~/stuff’ <enter> – to make sure where the next command is executed, since it writes a file.
  • Now type your 2nd command: ‘echo “Hello 8.00″ > hello.txt’ <enter>
  • The prompt shows another at>. If you have more commands add them. In our example we have only two. To finish we press STRG-D and you have your normal prompt back.
  • Type the command ‘atq’ to see the pending jobs in the queue. Your job, you just added has a job-ID in the first column.
  • To delete the job from the queue type ‘atrm <job-id>’.

Good timing!