Show Table of Contents
23.3. Scheduling a Job to Run at a Specific Time Using at
To schedule a one-time task, also called a job, to run once at a specific time, use the
at utility.
Users specify
at jobs using the at utility. The jobs are then executed by the atd service.
23.3.1. Prerequisites for At Jobs
Before scheduling an
at job:
- Install the at package:
~]#
yum install at - The
atdservice is enabled - made to start automatically at boot time - upon installation. If you disabled the service, enable it:~]#
systemctl enable atd.service - Start the
atdservice for the current session:~]#
systemctl start atd.service
23.3.2. Scheduling an At Job
- A job is always run by some user. Log in as the desired user and run:
~]#
at timeReplace time with the time specification.For details on specifying time, see the at(1) manual page and the/usr/share/doc/at/timespecfile.Example 23.1. Specifying Time for At
To execute the job at 15:00, run:~]#
at 15:00If the specified time has passed, the job is executed at the same time the next day.To execute the job on August 20 2017, run:~]#
at August 20 2017or~]#
at 082017To execute the job 5 days from now, run:~]#
now + 5 days - At the displayed
at>prompt, enter the command to execute and press Enter:~]#
at 15:00at> sh /usr/local/bin/my-script.sh at>Repeat this step for every command you want to execute.Note
Theat>prompt shows which shell it will use:warning: commands will be executed using /bin/sh
The at utility uses the shell set in user's SHELL environment variable, or the user's login shell, or/bin/sh, whichever is found first. - Press Ctrl+D on an empty line to finish specifying the job.
Note
If the set of commands or the script tries to display information to standard output, the output is emailed to the user.
Viewing Pending Jobs
To view the list of pending jobs, use the
atq command:
~]# atq
26 Thu Feb 23 15:00:00 2017 a root
28 Thu Feb 24 17:30:00 2017 a root
Each job is listed on a separate line in the following format:
job_number scheduled_date scheduled_hour job_class user_name
The
job_queue column specifies whether a job is an at or a batch job. a stands for at, b stands for batch.
Non-root users only see their own jobs. The root user sees jobs for all users.
Deleting a Scheduled Job
To delete a scheduled job:
- List pending jobs with the
atqcommand:~]#
atq26 Thu Feb 23 15:00:00 2017 a root 28 Thu Feb 24 17:30:00 2017 a root - Find the job you want to delete by its scheduled time and the user.
- Run the
atrmcommand, specifying the job by its number:~]#
atrm26
23.3.2.1. Controlling Access to At and Batch
You can restrict access to the
at and batch commands for specific users. To do this, put user names into /etc/at.allow or /etc/at.deny according to these rules:
- Both access control files use the same format: one user name on each line.
- No white space is permitted in either file.
- If the
at.allowfile exists, only users listed in the file are allowed to useatorbatch, and theat.denyfile is ignored. - If
at.allowdoes not exist, users listed inat.denyare not allowed to useatorbatch. - The
rootuser is not affected by the access control files and can always execute theatandbatchcommands.
The
at daemon (atd) does not have to be restarted if the access control files are modified. The access control files are read each time a user tries to execute the at or batch commands.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.