at


The /usr/bin/at command is used to submit jobs for later execution. Jobs submitted with at are run once at the specified time.

Specify the script or binary to run along with the time specification. Here are a few examples showing how a database administrator could submit a job to run a daily report:

at -f /prod_serv/scripts/prod_daily_report now + 1 minute at -f /prod_serv/scripts/prod_daily_report now + 1 hour at -f /prod_serv/scripts/prod_daily_report 13:55 at -f /prod_serv/scripts/prod_daily_report 4am + 3 days


The time specification format is very flexible. See the at(1) man page and /usr/share/doc/at-3.1.8/timespec for more details. Jobs submitted with at inherit the environment variables of the shell from which they were submitted.

Several more commands are provided with the at package. See the man page for a complete list and description. Here are a few useful examples.

To list jobs that are queued, use this command:

# atq 5        2004-08-18 04:00 a root 4        2004-08-15 14:54 a root


To remove a job with an ID number of 4, use this command:

# atrm 4 # atq 5       2004-08-18 04:00 a root


Linux provides a batch command that works similarly to at, except that the command runs when the load average of the system is less than .8 or the value specified with the atrun command. See the next topic for details on atrun. An execution time is not specified when submitting a job with the batch command. For example:

# batch -f /prod_serv/scripts/prod_daily_report


The /etc/at.allow and /etc/at.deny files can be used to control which users can run at and batch. Their format and use are the same as cron's allow and deny files.

at jobs are queued as files in /var/spool/at in Red Hat and /var/spool/atjobs in SUSE. The job files are plain text files.

at Daemon and atrun

Jobs submitted using at are started either by a daemon atd process or by the atrun script. The newer method is to have atd run as a daemon. You can determine whether atd is started as a daemon by using chkconfig:

#chkconfig --list atd atd             0:off    1:off    2:off    3:on    4:on    5:on    6:off


Here we see atd is started at runlevels 3, 4, and 5. If atd is not started as a daemon at startup, the atrun script should be started by cron periodically to run the at jobs. atrun is just a simple script to run atd:

#! /bin/sh prefix=/usr exec_prefix=/usr exec /usr/sbin/atd -s "$@"


The at README (/usr/share/doc/at-3.1.8/README) suggests adding a line to root's crontab file to start atrun every five minutes:

* * * * 0,5,10,15,20,25,30,35,40,45,50,55 /usr/sbin/atrun


If atd runs as a daemon, the at jobs run instantly. The cost is one additional process as overhead, but that is a small price to pay. If atrun is started with the previous crontab entry, the at jobs are checked only every five minutes. The atrun command can be executed with the -l load average parameter to specify the load average at which jobs submitted with batch will run.

Here are the files delivered with the Red Hat 9.0 at package:

# rpm -q --filesbypkg at at                       /etc/at.deny at                       /etc/rc.d/init.d/atd at                       /usr/bin/at at                       /usr/bin/atq at                       /usr/bin/atrm at                       /usr/bin/batch at                       /usr/sbin/atd at                       /usr/sbin/atrun at                       /usr/share/doc/at-3.1.8 at                       /usr/share/doc/at-3.1.8/ChangeLog at                       /usr/share/doc/at-3.1.8/Copyright at                       /usr/share/doc/at-3.1.8/Problems at                       /usr/share/doc/at-3.1.8/README at                       /usr/share/doc/at-3.1.8/timespec at                       /usr/share/man/man1/at.1.gz at                       /usr/share/man/man1/atq.1.gz at                       /usr/share/man/man1/atrm.1.gz at                       /usr/share/man/man1/batch.1.gz at                       /usr/share/man/man5/at.allow.5.gz at                       /usr/share/man/man5/at.deny.5.gz at                       /usr/share/man/man8/atd.8.gz at                       /usr/share/man/man8/atrun.8.gz at                       /var/spool/at at                       /var/spool/at/.SEQ at                       /var/spool/at/spool




Linux Troubleshooting for System Administrators and Power Users
Real World Mac Maintenance and Backups
ISBN: 131855158
EAN: 2147483647
Year: 2004
Pages: 129
Authors: Joe Kissell

Similar book on Amazon

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