Using the at Daemon

Using the at Daemon

One of the drawbacks of a cron job is that it is scheduled to be run on a regular basis. Sometimes, you just want to run a specific task once and then forget it. That s where the at daemon comes in.

It s easy to set up an at job. You can specify the time when you want to run the program, or you can use the associated batch command to start the job when your computer is relatively free.

This daemon works more like the print process; jobs are spooled in the /var/spool/at directory and executed at the desired time.

Setting Up an at Job

The at daemon works almost as if it were a separate shell. When you run the at time command, it sends you to a command prompt where you can enter the commands and programs of your choice. The at now + time command works as well; the job is run after a specified time period has passed.

For example, assume you re working on a large database and want to process the data when nobody else will be using the system, say at 2:05 a.m . You ve set up the /home/mj/airplane script to manage your database, and plan to process the results in the /home/mj/air-safe file. The normal way to do this is with the following commands:

 #  at 2:05 tomorrow  at>  /home/mj/airplane  >  /home/mj/air-safe  at> Ctrl-D 

There are a number of different ways to set up the time in the at + time command, as shown in Table 13.2.

Table 13.2: at Daemon Time Parameters

Period

Example

Comment

Minute

at now + 5 minutes

The jobs will start in 5 minutes.

Hour

at now + 1 hour

The jobs will start in 1 hour.

Days

at now + 3 days

The jobs will start in 3 days.

Weeks

at now + 2 weeks

The jobs will start in 2 weeks.

Fixed

at midnight

The jobs will start at midnight.

Fixed

at 10:30pm

The jobs will start at 10:30 . p.m.

Fixed

at 1:00 5/12/03

The jobs will start on May 12, 2003, at 1 a.m .

Job Queue

Once you ve entered a job, you can make sure that it s in the queue by using the atq command. As you can see, the output gives you the job number, the responsible user , and the time when the job is to be executed. The letter before the username ( a or b ) indicates whether it s an at or a batch job.

 #  atq  8    2003-03-08 02:05 a mj 

It s easy to remove a job. Just use the atrm jobnumber command. For example, the following command deletes job 8 from the queue:

 # atrm 8 

Batch Jobs

The batch command is a specialized version of at that runs at jobs. By default, jobs created with this command run only when the demand on your CPU is below 80 percent of its capacity.

The batch command is equivalent to the at -q b command.

Security

Similar to the cron daemon, at uses the /etc/at.allow and /etc/at.deny files to regulate access to this system. By default, Red Hat Linux installs a blank /etc/at.deny file. This allows all users access to the at system.

As long as the /etc/at.allow file does not exist, only the users listed in /etc/at.deny are denied use to at . If you add users to /etc/at.allow , only those users are allowed to use the at command. In this case, the /etc/at.deny file is ignored.

 


Mastering Red Hat Linux 9
Building Tablet PC Applications (Pro-Developer)
ISBN: 078214179X
EAN: 2147483647
Year: 2005
Pages: 220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net