RHCSA Rapid Track
Course update
An updated version of this course is available that uses a newer version of Red Hat Enterprise Linux in the lab environment. Therefore, the RHEL 9.0 version of the lab environment will retire on December 31, 2024. Please complete any work in this lab environment before it is removed on December 31, 2024. For the most up-to-date version of this course, we recommend moving to the RHEL 9.3 version.
In this exercise, you schedule commands to run on various schedules by adding configuration files to the system crontab directories.
Outcomes
Schedule a recurring system job to count the number of active users.
Update the
systemdtimer unit that gathers system activity data.
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-system
Instructions
Log in to the
serveramachine as thestudentuser and switch to therootuser.[student@workstation ~]$
ssh student@servera...output omitted... [student@servera ~]$sudo -i[sudo] password for student:student[root@servera ~]#Schedule a recurring system job that generates a log message to indicate the number of active users in the system. This job must run daily and use the
w -h | wc -lcommand to retrieve the number of active users in the system. Use theloggercommand to generate the log message of currently active users.Create the
/etc/cron.daily/usercountscript file with the following content:#!/bin/bash USERCOUNT=$(w -h | wc -l) logger "There are currently ${USERCOUNT} active users"Make the script file executable.
[root@servera ~]#
chmod +x /etc/cron.daily/usercount
Install the
sysstatpackage. The timer unit must trigger the service unit every ten minutes to collect system activity data with the/usr/lib64/sa/sa1shell script. Change the timer unit configuration file to collect the system activity data every two minutes.Install the
sysstatpackage.[root@servera ~]#
dnf install sysstat...output omitted... Is this ok [y/N]:y...output omitted... Complete!Copy the
/usr/lib/systemd/system/sysstat-collect.timerfile to the/etc/systemd/system/sysstat-collect.timerfile.[root@servera ~]#
cp /usr/lib/systemd/system/sysstat-collect.timer \/etc/systemd/system/sysstat-collect.timerEdit the
/etc/systemd/system/sysstat-collect.timerfile for the timer unit to run every two minutes. Replace any occurrence of the10 minutesstring with2 minutesthroughout the unit configuration file, including the occurrences in the commented lines. Use thevim /etc/systemd/system/sysstat-collect.timercommand to edit the configuration file.From these changes, the
sysstat-collect.timerunit triggers thesysstat-collect.serviceunit every two minutes, and collects the system activity data in a binary file in the/var/log/sadirectory....output omitted... # Activates activity collector every 2 minutes [Unit] Description=Run system activity accounting tool every 2 minutes [Timer] OnCalendar=*:00/2 [Install] WantedBy=sysstat.serviceNotify the
systemddaemon of the changes.[root@servera ~]#
systemctl daemon-reloadActivate the
sysstat-collect.timerunit.[root@servera ~]#
systemctl enable --now sysstat-collect.timer...output omitted...Wait until the binary file is created in the
/var/log/sadirectory.The
whilecommand,ls /var/log/sa | wc -lreturns0when the file does not exist, or returns1when the file exists. Thewhilecommand pauses for one second when the file is not present. Thewhileloop exits when the file is present.[root@servera ~]#
while [ $(ls /var/log/sa | wc -l) -eq 0 ]; \do sleep 1s; doneVerify that the binary file in the
/var/log/sadirectory was modified within two minutes.[root@servera ~]#
ls -l /var/log/satotal 4 -rw-r--r--. 1 root root 2540 Apr 5 04:08sa05[root@servera ~]#dateTue Apr 5 04:08:29 AM EDT 2022Return to the
workstationmachine as thestudentuser.[root@servera ~]#
exitlogout [student@servera ~]$exitlogout Connection to servera closed. [student@workstation ~]$
This concludes the section.