In this exercise, you 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 to servera as the student user.
[student@workstation ~]$ ssh student@servera
...output omitted...
[student@servera ~]$Schedule a job to run in two minutes from now.
Save the output of the date command to the /home/student/myjob.txt file.
Pass the date >> /home/student/myjob.txt string as the input to the at command, so that the job runs in two minutes from now.
[student@servera ~]$ echo "date >> /home/student/myjob.txt" | at now +2min
warning: commands will be executed using /bin/sh
job 1 at Thu Feb 16 18:51:16 2023List the scheduled jobs.
[student@servera ~]$ atq
1 Thu Feb 16 18:51:16 2023 a studentMonitor the deferred jobs queue in real time.
After the atd daemon executes, it removes the job from the queue.
The command updates the output of the atq command every two seconds, by default.
After the atd daemon removes the deferred job from the queue, press Ctrl+c to exit the watch command and return to the shell prompt.
[student@servera ~]$ watch atq
Every 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.txt file match the output of the date command.
The output matches the output of the date command, which confirms that the scheduled job executed successfully.
[student@servera ~]$ cat myjob.txt
Thu Feb 16 06:51:16 PM EDT 2023Interactively schedule a job in the g queue that runs at teatime (16:00).
The job should print the It's teatime message to the /home/student/tea.txt file.
Append the new messages to the /home/student/tea.txt file.
[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 2023
Interactively schedule another job with the b queue that runs at 16:05.
The job should print The cookies are good message to the /home/student/cookies.txt file.
Append the new messages to the /home/student/cookies.txt file.
[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 2023
Inspect 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 student3
View the commands in the pending job number 2. Replace the job number if it changed for you.
The job executes an echo command that appends the It's teatime message to the /home/student/tea.txt file.
[student@servera ~]$at -c...output omitted...2echo "It's teatime" >> /home/student/tea.txtmarcinDELIMITER1d7be6a7
View the commands in the pending job number 3. Replace the job number if it changed for you.
The job executes an echo command that appends the message The cookies are good to the /home/student/cookies.txt file.
[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 the atrm command.
[student@servera ~]$atq2Fri Feb 17 16:00:00 2023 g student3Fri Feb 17 16:05:00 2023 b student [student@servera ~]$atrm 2
Verify 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 student
Return to the workstation machine as the student user.
[student@servera ~]$ exit
logout
Connection to servera closed.
[student@workstation ~]$This concludes the section.