# 14-A.1: Job Scheduling - at Command

EXAM OBJECTIVES COVERED
2.6 Given a scenario, automate and schedule jobs.

## Objectives of this Module

In this lesson, you will:

• Learn to run jobs on a set schedule
• Configure and run version control for files using Git
• Describe concepts fundamental to orchestration

## The at Command

The at command is a command-line utility that is used to schedule a command to be executed at a particular time in the future. Jobs created with at command are executed only once. The at command can be used to execute any program or mail at any time in the future. It executes commands at a particular time and accepts times of the form HH:MM to run a job at a specific time of day. The following expressions like noon, midnight, teatime, tomorrow, next week, next Monday, etc. could be used with at command to schedule a job.

Syntax:

at [ OPTION ] runtime

Options:

Options Option Meaning
-m Sends mail to the user when the job has completed even if there was no output.
-f file Reads the job from file rather than standard input.
-l Is an alias for atq.
-d Is an alias for atrm.
-v Shows the time the job will be executed before reading the job.
-c Cats the jobs listed on the command line to standard output.
-t time_arg Submits the job to be run at the time specified by the time_arg option argument, which must have the same format as specified for the touch(1) utility's -t time option argument ([[CC]YY]MMDDhhmm).

The runtime argument has a rather vague syntax. The following table shows numerous examples of this syntax. This assumes the current time is Wed Nov 18 08:00:00 PST 2020.

Time Expression Time of Command Execution
noon

12:00 PM November 18 2020

midnight

12:00 AM November 19 2020

tomorrow

8:00 AM November 19 2020

noon tomorrow

12:00 PM November 19 2020

next week

8:00 AM November 25 2020

next Monday

8:00 AM November 23 2020

fri

8:00 AM November 20 2020

6:00 AM

6:00 AM November 19 2020

2:30 PM

2:30 PM November 18 2020

1430

2:30 PM November 18 2020

2:30 PM tomorrow

2:30 PM November 19 2020

2:30 PM next month

2:30 PM December 18 2020

2:30 PM 11/21

2:30 PM November 21 2020

2:30 PM Nov 21

2:30 PM November 21 2020

2:30 PM 11/21/2020

2:30 PM November 21 2020

now + 30 minutes

8:30 AM November 18 2020

now + 1 hour

9:00 AM November 18 2020

now + 2 days

8:00 AM November 20 2020

4 PM + 2 days

4:00 PM November 20 2020

now + 3 weeks

8:00 AM December 8 2020

now + 4 months

8:00 AM March 18 2021

There are four commands that are part of the at command set:

Command Explanation
at Executes commands at a specified time.
atq Lists the user's pending jobs, unless the user is the superuser; in that case, everybody's jobs are listed. The format of the output lines (one for each job) is: Job number, date, hour, queue, and username.
atrm Deletes jobs, identified by their job number.
batch Executes commands when system load levels permit; in other words, when the load average drops below 0.8, or the value specified in the invocation of atd.

The following example illustrates some of the at command: 1) set the execution to 30 minutes from the current time; 2) the "at>" prompt we type in commands; 3) the <EOT> happens when we enter a ctrl-D (control-d keys pressed simultaneously); 4) atq show all at commands in our queue; 5) atrm removes the command sitting in the number 2 slot in our queue - which we obtained from the output of atq; 6) the second atq shows nothing in the queue.

pbmac@pbmac-server $at now + 30 minutes warning: commands will be executed using /bin/sh at> echo "Hello World" at> <EOT> job 2 at Wed Nov 25 13:33:00 2020 pbmac@pbmac-server$ atq
2    Wed Nov 25 13:33:00 2020 a pbmac
pbmac@pbmac-server $atrm 2 pbmac@pbmac-server$ atq
pbmac@pbmac-server \$