Scheduling with "at"

Schedule tasks in Linux with the "at" command

At, atq and atrm Commands

Allow jobs to be executed in the future at a predefined date or time. Generally the "at" command is used to schedule your job/script, "atq" is used to show jobs waiting to run and "atrm" is used to remove jobs from the queue. At is used normally when you need to run a job only once at a certain time/date.

Examples of the at command

In the following example, we run the command echo "hello" at the specified time of 11:46

sles01:/home/john # echo "hello" > /tmp/hello.txt | at 11:46
warning: commands will be executed using /bin/sh
job 7 at 2013-05-07 11:46

The command will execute at the specified time. Below is the output from the above scheduled command:

sles01:/home/john # ls -l /tmp/hello.txt
-rw-r--r-- 1 root root 6 May  7 11:45 /tmp/hello.txt
sles01:/home/john # cat /tmp/hello.txt

In the next example of the "at" command, we schedule the same command to run at 11:50. After submitting our job, we run the "at -l" command and the "atq" command to confirm our job is waiting to execute:

sles01:/home/john # echo "hello" > /tmp/hello.txt | at 11:50
warning: commands will be executed using /bin/sh
job 8 at 2013-05-07 11:50

The number indicated before the date refers to the job queue number. In our example this is eight.

sles01:/home/john # atq
8       2013-05-07 11:50 a root

sles01:/home/john # at -l
8       2013-05-07 11:50 a root

Notice, the "atq" command and the "at -l" command both display outstanding jobs.

If you submit a job and change and then decide you no longer wish that particular job to run, you can remove the job from the queue with the "atrm" command. In the example below, we are removing job number "8"

sles01:/home/john # atrm 8
sles01:/home/john # atq

The "at" command can also be used to schedule the running of a script at a specified time. This is achieved by using the "-f" option (file):

sles01:/home/john # echo -f /home/john/ | at 11:55
warning: commands will be executed using /bin/sh
job 9 at 2013-05-07 11:55

sles01:/home/john # atq
9       2013-05-07 11:55 a root

The above command will schedule job "" to run at 11:55, we can also see that it has been assigned the job queue number of "9".

at time options

The "at" command accepts times of the form HH:MM to run a job at a specific time of day.
(If that time is already past, the next day is assumed.)

You may also specify midnight, noon, or teatime (4pm) and you can have a time-of-day suffixed with AM or PM for running in the morning or the evening.

You can also say what day the job will be run, by passing a date in the form month-name day with an optional yearYou can also specify the date in the following format MMDD[CC]YY, MM/DD/[CC]YY, DD.MM.[CC]YY or [CC]YY-MM-DD.

The specification of a date must follow the specification of the time of day.

You can also give times like now + count time-units, where the time-units can be minutes, hours, days, or weeks. You can tell "at" to run the job today by suffixing the time with today and to run the job tomorrow by suffixing the time with tomorrow.

"at" permissions

The "root" user is able to run the "at" command, however, normal users will need to have the necessary privileges granted. The location of these privileges can be found in "/etc/at.allow and "/etc/at.deny files.

The files "/etc/at.allow" and "/etc/at.deny" determine which users can submit commands for later execution.

The format of these files is a list of user names, one per line. White space is not permitted.

If the file "/etc/at.allow" exists,then only user names mentioned in it are allowed to use "at".

If the file "/etc/at.allow" does not exist, then the file "/etc/at.deny" is checked, every username not mentioned in it is then allowed to use at.

If the file "/etc/at.deny" is empty, then this means that every user may use the "at" command.

If neither of the files exist, then only the "superuser" is allowed to use at.