14-A.1: Job Scheduling - at Command
- Page ID
- 43471
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)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.
A bit of a video overview of using the at command to show some examples before we get into the details.
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 expressions like noon, midnight, teatime, tomorrow, next week, next Monday, etc. could be used with at command to schedule a job. This 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 $
Adapted from:
"at Command in Linux with Examples" by vizvasya, Geeks for Geeks is licensed under CC BY-SA 4.0