Running Jobs Once

We've talked at length about crond and its ability to run many scheduled jobs over a 24-hour period. Suppose, though, that you have a job you'd like to run unattended, but only once. Surely you don't have modify the crontab file for a single execution then remove the entry. Indeed not. Linux distributions contain the right tool for just such a situation - the at program

at require very few parameters. First, you'll need to enter the time at which you'd like the job to be executed. Then, you'll need to enter all the commands to be executed by the job. Finally, Ctrl-D submits the job, returning a job number, date and time. At this point, an example is useful.

You're an avid Mozilla user. You know that Mozilla releases "daily builds" on the mozilla.org site each night, and you'd like to see what's up with your favorite browser. However, you'd like to schedule the download at an off-peak time and have the unzipped and untarred file waiting in the morning. Here's how you would use at to complete the task:

    at 02:00 [ret]
    at> mkdir /home/tony/mozilla-nightly [ret]
    at> cd /home/tony/mozilla-nightly [ret]
    at> ncftpget -v ftp://ftp.mozilla.org/pub/mozilla/nightly/latest/mozilla-i686-pc-linux-gnu.tar.gz [ret]
    at> tar zxvf mozilla-i686-pc-linux-gnu.tar.gz [Ctrl-D]

ncftpget, by the way, is a program to download files via ftp without actually sitting at your computer. In our example, Ctrl-D schedules the job as entered and escapes, printing something like the following:

    job 1 at 2002-02-08 02:00

If you're like me, you're likely to enter a few jobs, then forget what they were. You can always review outstanding at jobs with the atq command. This command returns a list of the scheduled jobs by job number.

Now the real fun - put the at command to good use on your own system, completing one-time jobs unattended and behind your back.

 

Reply via email to