24.3 Automating Jobs Using the at Command

   

The at command is used to execute a job at a particular time only once compared with crontab , where jobs are executed repeatedly. The cron daemon is responsible for executing at jobs at the required time. A record of spooled at jobs is created in the /var/spool/cron/atjobs directory, where a separate file is created for each job. This file contains commands to be executed and the values of environment variables .

Submitting a Job

To submit a job, you start the at command on the command line by specifying the time at which the job is to be scheduled. After that, you type in the commands that are to be executed at that time. When you have finished entering the commands, use the graphics/controld.gif key combination to end the command entering process. A sample session used with the at command is as follows .

 #  at -t 12081210  /home/root/trimlog CTRL-D job 945018720.a at Sun Dec 08 12:10:00 1999 # 

Here you have used the at command to execute a job on December 8, 1999 at 12:10 a.m. After you start the command on the command line with the time, you go to the next line, which is blank. Here you type the command that is to be executed at the specified time. You can enter multiple commands or program names by pressing the graphics/enter.gif key and going to the next line. When you have finished entering the command names, pressing the graphics/controld.gif key combination will end the at session, and you will get back the command prompt.

When you press the graphics/controld.gif combination to end entering command names, the at command displays a line showing you that a job has been scheduled. It shows the job ID and the time at which the job will be executed.

You can specify time with the at command in a number of ways, as shown in the following examples.

 at 1210 Dec 08 at 12:10 Dec 08 at 12:10am tomorrow at now + 1 day at now + 10 minutes 

The first and second examples have the same time setting as you have already used. In the third example, the job will be executed at 12:10 a.m. the next day. In the fourth example, the job will be executed at the current time tomorrow. In the last example, the job will be executed after 10 minutes.

You can also list commands or jobs to be executed in a file and then specify that file name on the command line with the at command. In the following example, a file named myfile contains commands to be executed after one hour .

 at -f myfile now + 1 hour 

Listing and Deleting at Jobs

To list the current jobs, you can use the at -l command as shown here.

 #  at -l  945018720.a     Sun Dec 08 12:10:00 1999 # 

This command lists job IDs and the time at which these jobs will be executed. To remove the above job, use the following command containing the job ID.

 at -r 945018720.a 

When you submit a job, a spool file is created in the /var/spool/cron/atjobs directory. This file has the same name as the job ID and contains commands to create environment variable values that were present at the time of submitting the job in addition to a list of commands that will be executed. The file created by the above job is shown here.

 #  cat /var/spool/cron/atjobs/945018720.a  : at job export _; _=/usr/bin/at export MANPATH; MANPATH=/usr/share/man/%L:/usr/share/man:/   usr/contrib/man/%L:/usr/contrib/man:/usr/local/man/%L:/   usr/local/man:/optn export PATH; PATH=/usr/bin:/usr/ccs/bin:/usr/contrib/bin:/   opt/nettladm/bin:/opt/pd/bin:/usr/bin/X11:/usr/contrib/   bin/X11:/opt/upgra. export EDITOR; EDITOR=vi export LOGNAME; LOGNAME=root export MAIL; MAIL=/var/mail/root export ERASE; ERASE=\^H export SHELL; SHELL=/usr/bin/sh export HOME; HOME=/home/root export TERM; TERM=vt320 export PWD; PWD=/home/root export TZ; TZ=EST5EDT export LINES; LINES=24 # @(#) Revision: 27.1 cd /home/root ulimit 4194304 umask 22 /home/root/trimlog # 

The variables are saved to create the same environment as the user is using at the time of submitting the job. When cron runs the job, it creates a shell and executes the commands in this file to create the environment and then executes the actual job. Note that the programs or command names submitted with the at command are present in the last line of the output.

Allowing/Denying User Access

Like crontab , use of the at command can also be restricted using the /var/adm/cron/at.allow and /var/adm/cron/at.deny files. The effect of these two files is identical to the one used with the cron.allow/cron.deny files and is listed in Table 24-2.

Table 24-2. Roles of the at Files to Allow/Deny Use of the at Command
at.allow at.deny Effect on User
Not exists Not exists Only the root user can use at .
Not exists Exists All users except those listed in at.deny can use at .
Not exists Exists (empty) All users can use at .
Exists Not exists Only those users listed in the at.allow can use at .
Exists Exists Only those users listed in the at.allow can use at .
Exists (empty) Not exists Only the root user can use at .
Exists (empty) Exists Only the root user can use at .

Warning

You must be careful of the case where at.allow does not exist and at.deny exists but is empty. In this case, all users of the system are granted at access.



   
Top


HP Certified
HP Certified: HP-UX System Administration
ISBN: 0130183741
EAN: 2147483647
Year: 2000
Pages: 390
Authors: Rafeeq Rehman

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