If you want to schedule a job to run one time only in the future (instead of scheduling it on a regular basis with cron) you can use the at command. To use at, you must first verify that the at package has been installed and that the atd service has been started.
You define an at job at the command prompt by entering at launch_time, where launch_time is the time when you want the job to begin. (For example – 12:34). Then you enter the commands you want at to run one line at a time at the at> prompt. When you finish entering commands, you save the job by pressing Ctrl+d.
The following is an example of creating a job with the at command:
# at 10:40 at> echo "Hello World" > /tmp/out at> [EOT] job 3 at Sun Dec 17 10:40:00 2017
To view the at jobs queue use the atq command. For example:
# atq 2 Sun Dec 17 10:37:00 2017 a root 3 Sun Dec 17 10:40:00 2017 a root
The number in the first column is the job ID of the at job. To remove a job from the at queue before the job can be executed, use the atrm command.
# atrm [job_ID]
For Example :
# atrm 2
You can also enter the commands you want to be executed by at in a text file. If you do this, then you need to enter ‘at -f file launch_time‘ at the shell prompt, where the file is the path and filename of the file.
The following table list some other commonly used at commands and options:
Command | Description |
---|---|
atq | Displays defined jobs (including job numbers, which are needed to delete a job) |
atrm job_number | Deletes a job (using the job number) |
As with cron, you can restrict access to the atd daemon. Two files determine which users can run the at command:
- /etc/at.allow: Users entered in this file can define jobs.
- /etc/at.deny: Users who are not listed in this file can define jobs.
These files are text files you can modify or create. If the /etc/at.allow file exists, only this file is evaluated. If neither of these files exists, only the user root can define at jobs.