Configure a custom systemd service and associated timer to perform automated metric logging on a recurring schedule.
Requirements
Create a service unit file named /etc/systemd/system/syslog-check.service.
The service must be of type oneshot.
It must execute the command /usr/bin/logger "RHCSA Performance Check Active" upon activation.
Create a timer unit file named /etc/systemd/system/syslog-check.timer.
The timer must trigger syslog-check.service.
The timer must execute every Monday through Friday at 08:30:00 and 16:30:00.
Ensure the timer starts automatically upon system boot and is activated (not start) immediately without restarting the system.
Solution
Create .service unit file
sudo touch /etc/systemd/system/syslog-check.service
Open .service unit file by vim
sudo vim /etc/systemd/system/syslog-check.service
Write content of .service unit file
Press I to enter insert mode
[Unit]
Description=automated metric logging
[Service]
Type=oneshot
ExecStart=/usr/bin/logger "RHCSA Performance Check Active"
Save and exit
Esc --> :wq
Verify .service file content
cat /etc/systemd/system/syslog-check.service
Create .timer unit file
sudo touch /etc/systemd/system/syslog-check.timer
Open .timer unit file by vim
sudo vim /etc/systemd/system/syslog-check.timer
Write content of .timer unit file
Press I to enter insert mode
[Unit]
Description=automated metric logging timer
[Timer]
OnCalendar=Mon..Fri *-*-* 08,16:30:00
[Install]
WantedBy=timers.target
Save and exit
Esc --> :wq
Verify .timer file content
cat /etc/systemd/system/syslog-check.timer
Verify calendar expression
systemd-analyze calendar "Mon..Fri *-*-* 08,16:30:00"
Reload the systemd
systemctl daemon-reload
Enable the timer
systemctl enable --now syslog-check.timer
Verify timer
systemctl status syslog-check.service
systemctl status syslog-check.timer
systemctl list-timers syslog-check.timer
Cleanup
systemctl stop syslog-check.timer
sudo systemctl disable --now syslog-check.timer
sudo systemctl stop syslog-check.service
rm -f /etc/systemd/system/syslog-check.service
rm -f /etc/systemd/system/syslog-check.timer
sudo systemctl daemon-reload
Install system performance metrics tooling and configure automated system performance collection.
Requirements
Install the sysstat package on the system.
Enable and start the default systemd timer provided by sysstat to gather performance metrics automatically.
Trigger an immediate metric capture manually via systemd without modifying or waiting for the schedule.
Verify that performance collection logs are populated using the sar utility.
Solution
Install sysstat
dnf install -y sysstat
Enable timer
sudo systemctl enable --now sysstat-collect.timer
Start timer
sudo systemctl start sysstat-collect.service
Verify timer status
systemctl status sysstat-collect.timer
Verify performance collection logs
sar -A
Configure scheduled background execution for a specific system user using crontab.
Requirements
Configure a cron task for user student (or your non-root user).
The task must execute every 15 minutes between 09:00 and 17:00, only on Saturdays.
The command to execute is: /usr/bin/echo "Maintenance Window Active" >> /tmp/maintenance.log 2>&1
Do not edit system-wide cron files (/etc/crontab or /etc/cron.d/); configure this within the designated user's cron spool.
Solution
Open crontab
crontab -e -u student
Edit command in crontab
Press Esc --> I
Example: */15 9-17 * * SAT /usr/bin/echo "Maintenance Window Active" >> /tmp/maintenance.log 2>&1
Press Esc --> :wq --> Enter to save.
Verify command
crontab -l -u student
Remove the crontab job
crontab -r -u student
Verify
crontab -l -u student
Remove the output log file
sudo rm -f /tmp/maintenance.log
Schedule a single, non-recurring delayed job using atd.
Requirements
Ensure the atd service is active and set to start automatically on system boot.
Schedule a one-time execution job to run 20 minutes from the current system time.
The job must create a file at /tmp/at_execution_flag.txt containing the system hostname (hostname > /tmp/at_execution_flag.txt).
Solution
Enable and start the atd service
systemctl enable --now atd
systemctl start atd
systemctl status atd
Run at command at specific time
at now + 20 minutes
Add command to create file when time reach
hostname > /tmp/at_execution_flag.txt
Press Enter --> Ctrl+D to stop edit command
List all active jobs of at command
atq
Wait till time passed
date
List all file under the directory and find the file
ls /tmp
Verify content
cat /tmp/at_execution_flag.txt
Cleanup
rm -rf /tmp/at_execution_flag.txt
Configure systemd-tmpfiles to manage temporary directory persistence and automatic file cleanup rules.
Requirements
Create a custom configuration file named /etc/tmpfiles.d/custom-cleanup.conf.
Define a rule that automatically manages a directory at /var/tmp/app_cache:
Type: Directory creation (d)
Ownership: User root, Group root
Permissions: 0775
Age limit: Clean up any files/directories older than 5 days (5d)
Define a second rule within the same file for /tmp/volatile_data:
Type: Directory creation (d)
Ownership: User root, Group root
Permissions: 0700
Age limit: Clean up any files older than 12 hours (12h)
Enforce the creation of these paths immediately using systemd-tmpfiles without rebooting the system.
Solution
Create configuration file
sudo vim /etc/tmpfiles.d/custom-cleanup.conf
Press Esc --> I to add command
d /var/tmp/app_cache 0775 root root 5d
d /tmp/volatile_data 0700 root root 12h
Press Esc --> :wq to save and quit.
Run create command
systemd-tmpfiles --create /etc/tmpfiles.d/custom-cleanup.conf;
Confirm permissions is
drwxrwxr-x (0775), owned by root user and root group.
ls -ld /var/tmp/app_cache
drwx------ (0700), owned by root user and root group.
ls -ld /tmp/volatile_data
Cleanup
systemd-tmpfiles --remove /etc/tmpfiles.d/custom-cleanup.conf;
rm /etc/tmpfiles.d/custom-cleanup.conf
sudo rmdir /var/tmp/app_cache
sudo rmdir /tmp/volatile_data
ls -ld /var/tmp/app_cache /tmp/volatile_data /etc/tmpfiles.d/custom-cleanup.conf