At – Planning One-time Tasks

At – Planning One-time Tasks

At this point, we have become thoroughly familiar with the basic principles of task planning using the cron tool. In the GNU/Linux environment – and Unix in general – it is also possible to utilize one-time task planning using the at tool.

While cron enables us to set repeated actions, i.e., how often the given task is to be executed, at is used to set a one-time action, i.e., the time to elapse until it is executed.

The daemon itself that handles the execution of a planned task is called atd (at daemon) and it is necessary to have it running in the system. This can be verified using the command:

# service atd status

If it’s not running, launch it:

# service atd start

You can also use an older method in case the command above does not work in your system:

# /etc/init.d/atd start

Once the utility daemon is running, we can begin inputting one-time actions. At is very benevolent in this respect, allowing a wide variety of time entries to specify when the action is to be performed. Here are several examples:

Value Meaning
hh:mm Exact time
2AM 2:00 a.m.
2PM 2:00 p.m.
noon 12:00 p.m.
teatime 4:00 p.m.
midnight 0:00
now At the moment
now + n unit n units (m, h) from now

The entry itself is done by first entering the time specification via command prompt and confirming with Enter, followed by specifying the specific commands. To finish the entry, press [CTRL]+[D].

$ at 2:00
warning: commands will be executed using /bin/sh
at> wget http://www.example.com/file.pdf
at> [CTRL]+[D]
job 12 at 2013-09-13 10:34

If it seems something is missing, you would be correct – at allows you to specify a particular date for the command to be executed on. This means that we can set tasks to any day we want, not just the upcoming 24 hours. Let’s illustrate with one more table.

Value Meaning
today Today
tomorrow Tomorrow
MM/DD/YY or DD.MM.YY Month/day/year or day.month.year

The entry can then look something like this:

$ at 2am 12/15/15
warning: commands will be executed using /bin/sh
at> wget http://www.example.com/file.pdf
at> [CTRL]+[D]
job 12 at 2015-09-13 10:34

The command is to be executed on 15th December 2015 at 2:00 a.m.

Finishing off with one extra tidbit for script enthusiasts: Not only is at very useful as an interactive tool, but also in shell scripts. Such in-line entry can look as follows:

$ echo ‘wget http://www.example.com/file.pdf ‘ | at 2:00

Thank you for your attention. We hope that you have learned something from our GNU/Linux instructional series.

Author: Jirka Dvořák

Best articles

Cooling system with freecooling technology in the server room
dedicated server Dell in our portfolio
VPS and VDS with 50% reduction on the price