The at command will run a script at a specified time. The command is used by typing at and then the time you want the activity to occur. This will create the at> prompt enabling you to enter the commands you desire to run. When you are done press Control+D.
Here is the basic format for an at command:
at [-c | -k | -s] [-f filename] [-q queuename] [-m] -t time [date] [-l] [-r]
[-c | -k | -s] — refers to the shell you are using C, Korn or Bourne
You could create a file that would be run by at. For example a bash shell script.
-m send mail to the user when it is complete sent by default with /usr/sbin/sendmail
-d this is an alias for atrm which will delete at jobs
-v shows the time a job will be executed
-c cats job to standard output
-t set a time for job to run ([[CC]YY]MMDDhhmm)
-q queue The a queue is reserved for at and the b queue is reserved for batch. If you add a queue then that queue will increase in niceness, which means it will have less priority.
-V prints version number
Who can use at is controlled by /etc/at.allow and /etc/at.deny
If at.allow exists, only those in allow can use it. If at.deny exists and allow does not then everyone not in deny can use it. If neither exist only root can use it.
MMDDYY, MM/DD/YY, or MM.DD.YY formats
now + time the current time is in minutes, hours, days, or weeks. For example, now + 3 days
atq to view pending jobs
Here is an Example:
at> touch mkdir test
Unlike cron, these jobs will only run once.
-l list jobs
-d jobnumber delete a job
This example shows that the user root has two jobs waiting.
2 2005-09-11 09:07 a root
at -d job1
This will delete job1.
Practice Lab: Using at
This is simply an easy practice exercise to get familiar with at.
In order to get at to work the first thing you need to do is enter at in the terminal with a time:
Once you do this an at> will be shown on the screen. This is where you will enter your command. So if you wanted to create a directory called test in the /root directory enter this information for the command:
at> mkdir /test
When you hit enter the at> will show up again waiting for a second command you may want to provide. But if you are only doing one command the next thing you do is hit CTRL+D. This will install the at command you did and initiate the command.
Once you do CTRL+D it will list your job or jobs that are currently waiting
to happen. It will all look like this:
at> mkdir /root/test
job 1 at 2006-09-02 10:35
Now check to see if the /test directory was created.