How to use At

Being as I found the man files and the –help option for at unnecessarily cryptic, and that it seems impossible to get a useful answer from google for “How to use at” I thought I’d make an attempt at creating one now that I’ve managed to figure it out.

In case you are unaware, ‘at’ is a command which, under linux/unix operating systems, will allow you to run a command or group of commands at a specified time. It differs from cron in that, while both will allow you to schedule commands or scripts to run whenever you please, cron jobs will run repeatedly whenever the given time is matched (daily, hourly, weekly, monthly, or yearly..) while a job created using at will run only once. Useful for very specific reminders, or something you have to get done at a later date, but not now.

It also differs in that “How to use Cron” is a much more useful search phrase.

Using at is actually quite simple, so long as you know exactly how it operates. The main problem with the built-in help, is it includes no examples. All the pertinent information is spread out, and some of it isn’t included. So, here is how to use it to download a file at 9:30 pm on August 31, 2009

~/ $ at 21:30 083109

warning: commands will be executed using /bin/sh
at> cd ~/downloads
at> wget http://www.thatonesite.com/thatonefile.txt
at> <Ctrl+D>
job 8 at  Mon Aug 31 21:30:00 2009
~/ $

or, to run it today instead

~/$ at 21:30

And that’s it.

At <TIME> # Starts the editor prompting you for commands
Commands # Everything you type is queued to execute at the time you specified
<Ctrl+D>    # Submits the job. Just like sending a message using the console mail command.

You can also add -f ‘filename’, to use a script file instead of typing the commands manually.

Other commands you may like to know

atq (OR at -l)                    – Lists all jobs you have scheduled

atrm (OR at -d) #           – Removes a job you have scheduled, the job number is the first thing to appear in the list with atq

batch (OR at -qb now)   – will run the specified commands in the background, ensuring your system performance isn’t affected

The time has lots of fun permutations, which the man file does a pretty good job of explaining

At allows fairly complex time  specifications,  extending  the  POSIX.2
standard.   It  accepts  times of the form HH:MM to run a job at a spe-
cific time of day.  (If that time is already  past,  the  next  day  is
assumed.)   You  may  also specify midnight, noon, or teatime (4pm) and
you can have a time-of-day suffixed with AM or PM for  running  in  the
morning or the evening.  You can also say what day the job will be run,
by giving a date in the form month-name day with an optional  year,  or
giving a date of the form MMDDYY or MM/DD/YY or DD.MM.YY.  The specifi-
cation of a date must follow the specification of the time of day.  You
can  also  give times like now + count time-units, where the time-units
can be minutes, hours, days, or weeks and you can tell at  to  run  the
job  today by suffixing the time with today and to run the job tomorrow
by suffixing the time with tomorrow.


For example, to run a job at 4pm three days from now, you would do
at 4pm + 3 days; to run a job at 10:00am on July 31, you would do at
10am Jul 31; and to run a job at 1am tomorrow, you would do at 1am
tomorrow.

The exact  definition  of  the  time  specification  can  be  found  in
/usr/share/doc/at/timespec.

It should also be noted that commands executed using at will run in their own environment, completely disconnected from your open consoles or the X server. So you can’t use it to, say, open a video detailing your plans as a reminder, although you can open an mp3:)

However, in order to prevent it from closing out immediately after openning, you have to hold the job open somehow.

So

~/messages $ at now
warning: commands will be executed using /bin/sh
at> mplayer ~/messages/file.mp3
at> sleep 5
at> <EOT>
job 34 at Tue Aug 25 19:42:00 2009
~/messages $

works, while

~/messages $ at now
warning: commands will be executed using /bin/sh
at> mplayer ~/messages/file.mp3
at> <EOT>
job 35 at Tue Aug 25 19:43:00 2009
~/messages $

Will only play the first half second..for some reason.

Next Page »