Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

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:
  1. Install the at package:
    ~]# yum install at
  2. The atd service is enabled - made to start automatically at boot time - upon installation. If you disabled the service, enable it:
    ~]# systemctl enable atd.service
  3. Start the atd service for the current session:
    ~]# systemctl start atd.service

23.3.2. Scheduling an At Job

  1. A job is always run by some user. Log in as the desired user and run:
    ~]# at time
    Replace time with the time specification.
    For details on specifying time, see the at(1) manual page and the /usr/share/doc/at/timespec file.

    Example 23.1. Specifying Time for At

    To execute the job at 15:00, run:
    ~]# at 15:00
    If 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 2017
    ~]# at 082017
    To execute the job 5 days from now, run:
    ~]# now + 5 days
  2. At the displayed at> prompt, enter the command to execute and press Enter:
    ~]# at 15:00
    at> sh /usr/local/bin/
    Repeat this step for every command you want to execute.


    The at> 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.
  3. Press Ctrl+D on an empty line to finish specifying the job.


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:
  1. List pending jobs with the atq command:
    ~]# atq
    26      Thu Feb 23 15:00:00 2017 a root
    28      Thu Feb 24 17:30:00 2017 a root
  2. Find the job you want to delete by its scheduled time and the user.
  3. Run the atrm command, specifying the job by its number:
    ~]# atrm 26 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.allow file exists, only users listed in the file are allowed to use at or batch, and the at.deny file is ignored.
  • If at.allow does not exist, users listed in at.deny are not allowed to use at or batch.
  • The root user is not affected by the access control files and can always execute the at and batch commands.
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.