Red Hat System Administration II
Use the at command to schedule several commands to run at specified future times.
Outcomes
Schedule a job to run at a specified future time.
Inspect the commands that a scheduled job runs.
Delete the scheduled jobs.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start scheduling-at
Instructions
From
workstation, open an SSH session toserveraas thestudentuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$Schedule a job to run in two minutes from now. Save the output of the
datecommand to the/home/student/myjob.txtfile.Pass the
date >> /home/student/myjob.txtstring as the input to theatcommand, so that the job runs in two minutes from now.[student@servera ~]$
echo "date >> /home/student/myjob.txt" | at now +2minwarning: commands will be executed using /bin/sh job 1 at Thu Feb 16 18:51:16 2023List the scheduled jobs.
[student@servera ~]$
atq1 Thu Feb 16 18:51:16 2023 a studentMonitor the deferred jobs queue in real time. After the
atddaemon executes, it removes the job from the queue.The command updates the output of the
atqcommand every two seconds, by default. After theatddaemon removes the deferred job from the queue, press Ctrl+c to exit thewatchcommand and return to the shell prompt.[student@servera ~]$
watch atqEvery 2.0s: atq servera.lab.example.com: Thu Feb 16 17:58:50 2023 1 Thu Feb 16 18:51:16 2023 a studentVerify that the contents of the
/home/student/myjob.txtfile match the output of thedatecommand.The output matches the output of the
datecommand, which confirms that the scheduled job executed successfully.[student@servera ~]$
cat myjob.txtThu Feb 16 06:51:16 PM EDT 2023
Interactively schedule a job in the
gqueue that runs atteatime(16:00). The job should print theIt's teatimemessage to the/home/student/tea.txtfile. Append the new messages to the/home/student/tea.txtfile.[student@servera ~]$
at -q g teatimewarning: commands will be executed using /bin/sh at>echo "It's teatime" >> /home/student/tea.txtat>Ctrl+djob2at Fri Feb 17 16:00:00 2023Interactively schedule another job with the
bqueue that runs at16:05. The job should printThe cookies are goodmessage to the/home/student/cookies.txtfile. Append the new messages to the/home/student/cookies.txtfile.[student@servera ~]$
at -q b 16:05warning: commands will be executed using /bin/sh at>echo "The cookies are good" >> /home/student/cookies.txtat>Ctrl+djob3at Fri Feb 17 16:05:00 2023Inspect the commands in the pending jobs.
View the job numbers of the pending jobs.
Note the job numbers in the output, which might vary on your system. Use the job numbers from your system.
[student@servera ~]$
atqFri Feb 17 16:00:00 2023 g student2Fri Feb 17 16:05:00 2023 b student3View the commands in the pending job number 2. Replace the job number if it changed for you.
The job executes an
echocommand that appends theIt's teatimemessage to the/home/student/tea.txtfile.[student@servera ~]$
at -c...output omitted...2echo "It's teatime" >> /home/student/tea.txtmarcinDELIMITER1d7be6a7View the commands in the pending job number 3. Replace the job number if it changed for you.
The job executes an
echocommand that appends the messageThe cookies are goodto the/home/student/cookies.txtfile.[student@servera ~]$
at -c...output omitted...3echo "The cookies are good" >> /home/student/cookies.txtmarcinDELIMITER44662c6f
View the job number of a job that runs at
teatime(16:00), and remove it by using theatrmcommand.[student@servera ~]$
atq2Fri Feb 17 16:00:00 2023 g student3Fri Feb 17 16:05:00 2023 b student [student@servera ~]$atrm 2Verify that the scheduled job to run at
teatime(16:00) no longer exists.View the list of pending jobs, and confirm that the scheduled job to run at
teatime(16:00) no longer exists.[student@servera ~]$
atq3Fri Feb 17 16:05:00 2023 b studentReturn to the
workstationmachine as thestudentuser.[student@servera ~]$
exitlogout Connection to servera closed. [student@workstation ~]$