In this lab, you will work with recurring system jobs.
| Resources | |
|---|---|
| Files: |
|
| Machines: | desktopX |
Outcomes
A daily job to count the number of active users, and an updated cron job to gather system performance data.
Log into your desktopX system as student, then
elevate your privileges to root.
[student@desktopX ~]$su -Password:redhat
Create a new daily cron job that logs a message to the system log with the number of currently active users (w -h | wc -l). You can use the logger command to send messages to the system log.
Open a new file in /etc/cron.daily in an
editor, e.g., /etc/cron.daily/usercount.
[root@desktopX ~]#vim /etc/cron.daily/usercount
Write the script that logs the number of active users to the system log.
Insert the following in your editor:
#!/bin/bash
USERCOUNT=$(w -h | wc -l)
logger "There are currently ${USERCOUNT} active users"Make the script executable:
[root@desktopX ~]#chmod +x /etc/cron.daily/usercount
The sysstat package, when installed, has a cron job that runs every 10 minutes, collecting data using a command called sa1. Make sure this package is installed, then change this job to run every five minutes.
Make sure the sysstat package is installed.
[root@desktopX ~]#yum -y install sysstat
Find out in which file the sysstat package has configured the cron jobs. Cron jobs are generally configured in files marked as a configuration file for the package manager.
[root@desktopX ~]#rpm -qc sysstat
/etc/cron.d/sysstat looks promising.
Open /etc/cron.d/sysstat in an editor.
[root@desktopX ~]#vim /etc/cron.d/sysstat
Change */10 on the sa1 line to
*/5.
Save your changes and exit.
Monitor the files in /var/log/sa
to see when their sizes and timestamps change.
[root@desktopX ~]#watch ls -l /var/log/sa