Using at and batch to Schedule Tasks for Later
If you want to run a time-intensive task, but you do not want to do it while
you are logged in, you can tell Ubuntu to run it later with the at command,
which you must install. The package name is the same as the tool: at. To use
at, you need to tell it the time at which you want the task to run and then
press Enter. You then see a new prompt that starts with at>, and everything
you type there until you press Ctrl+D will be the commands that at will run.
When the designated time arrives, at performs each action individually and
in order, which means later commands can rely on the results of earlier
commands. In the following example, run at just after 8:00 p.m., at is used to
download and extract the latest Linux kernel at a time when the network
should be quiet:
Click here to view code image
matthew@seymour:~$ at now + 7 hours
at> wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-
3.0.tar.bz2
at> tar xvfjp linux-3.0.tar.bz2
at>
job 2 at 2011-07-08 20:01
Specifying now + 7 hours as the time does what you would expect: at
was run at 8:00 p.m., so the command will run just after 3:00 a.m.
If you have a more complex job, you can use the –f parameter to have at
read its commands from a file, like this:
Click here to view code image
echo wget http://www.kernel.org/pub/linux/kernel/v3.0/linux-
3.00.tar.bz2\;
tar xvfjp linux-3.0.tar.bz2 > myjob.job
at –f myjob.job tomorrow
As you can see, at is flexible about the time format it takes; you can specify
it in three ways:
Using the now parameter, you can specify a number of minutes, hours,
days, or weeks relative to the current time. For example, now + 4
weeks runs the command four weeks from today.
You can also specify several special times, including tomorrow,
midnight, noon, or teatime (4:00 p.m.). If you do not specify a
time with tomorrow, your job is set for precisely 24 hours from the
current time.