RHCSA (044): Season 2 - Scenario 19: Automating Archive Sorting

Podcast: The RHCSA Series Podcast

  • Season: 2 (Episodes 26A - 50)
  • Episode: 44
  • Title: RHCSA (044): Season 2 - Scenario 19: Automating Archive Sorting
  • Release date: December 15, 2026
  • Produced by: Djere Services Group
  • Associated article: https://djere.com/rhcsa-044-season-2-scenario-19-automating-archive-sorting.html

Episode 044 Executive Summary

In this Automating Archive Sorting RHCSA lab scenario, I start performing the lab after a 6 minute introduction by the podcast hosts. You will get the most out of this lab if you listen to the entire show and then try to practice the lab several times, either along with me or by yourself. This exercise brings together fundamental file operations and stream management on a Rocky Linux 10 server.

Candidates often struggle when asked to combine basic file management with standard stream redirection and background task scheduling. The deceptive part of this scenario is that finding and moving files is straightforward, but ensuring that all standard output and standard errors from an automated task are properly captured requires a solid grasp of how the bash shell handles file descriptors.

The core challenge is to create a dedicated user for archiving, generate sample log files, and write a command string that finds, moves, and logs the operation. You will use core utilities like find and mv along with append and standard error redirection operators, then schedule the task using cron. Finally, we will trigger the exact command manually and verify the output to prove the stream redirection works exactly as intended.

Keywords: linux file management, standard streams, io redirection, cron scheduling, user management

EPISODE 044: Automating Archive Sorting

Season:2
Difficulty:High
Objectives:Primary 1.8, 1.2; Secondary 4.5, 9.1
Lab Focus:linux file management, io redirection, cron scheduling, user management
URL:https://djere.com/rhcsa-044-season-2-scenario-19-automating-archive-sorting.html

1. SCENARIO BRIEF (THE PROBLEM)

The security team requires that raw log files from a temporary directory be moved daily to a dedicated user account for processing. You must configure the system to move these files automatically while ensuring that any standard output is appended to a success log, and any errors are captured in a separate error log. You will create the user, set up the test files, and implement the solution.


2. TASK ANALYSIS (THE "WHY")

  • 1.8 File Management: Using find and mv provides precise control over locating and relocating files based on specific criteria like name and type.
  • 1.2 I/O Redirection: Capturing standard output (stdout) and standard error (stderr) separately is critical for auditing background jobs.
  • 4.5 Scheduling: The cron daemon is the standard method for executing recurring administrative tasks without manual intervention.
  • 9.1 Users/Groups: Creating a dedicated service account limits access and follows the principle of least privilege.

3. SOLUTION STEPS

Step 1: Environment Setup (Root Only)

# Check if the cron daemon package is installed and use the OR operator to install it with dnf if missing
rpm -q cronie || dnf install -y cronie

# Enable and immediately start the crond service using systemctl to ensure scheduled tasks will run
systemctl enable --now crond

# Create a new user named archiver with a standard home directory using the -m flag
useradd -m archiver

# Create a parent and child directory structure for raw logs using the -p flag to avoid errors if the path exists
mkdir -p /var/tmp/raw_logs

# Generate three blank sample log files in the raw_logs directory to serve as our test data
touch /var/tmp/raw_logs/app1.log /var/tmp/raw_logs/app2.log /var/tmp/raw_logs/app3.log

# Recursively change the ownership of the raw_logs directory to the archiver user and group using the -R flag
chown -R archiver:archiver /var/tmp/raw_logs

Step 2: Core Implementation (Execute as archiver)

# Switch your session to the archiver user environment using the dash to load their full profile
su - archiver

# Create the destination directory where the processed logs will be stored
mkdir -p /home/archiver/processed

# Schedule a cron job by echoing the schedule and command, then piping it to crontab - to read from standard input
# The job runs at 2 AM daily (0 2 * * *)
# It uses find to locate .log files and -exec mv to move them
# Standard output is appended (>>) and standard error (2>>) is appended to separate files

echo "0 2 * * * find /var/tmp/raw_logs/ -name '*.log' -type f -exec mv {} /home/archiver/processed/ \; >> /home/archiver/archive_out.txt 2>> /home/archiver/archive_err.txt" | crontab -

# Technical Breakdown: The find command locates items matching the string "*.log" that are regular files (-type f). The -exec flag runs the mv command on each found item, represented by the curly braces, and terminates the exec string with an escaped semicolon.
# Pro-Tip: When redirecting inside a cron job, always use absolute paths for the output files to guarantee they are written to the correct location regardless of the cron execution environment.

Step 3: Verification (The "Proof of Work")

# List the current cron jobs for the active user using the -l flag to verify the schedule was saved
crontab -l
- EXPECTED: 0 2 * * * find /var/tmp/raw_logs/ -name '*.log' -type f -exec mv {} /home/archiver/processed/ \; >> /home/archiver/archive_out.txt 2>> /home/archiver/archive_err.txt

# Manually execute the exact command string from the cron job to verify file movement and redirection
find /var/tmp/raw_logs/ -name '*.log' -type f -exec mv {} /home/archiver/processed/ \; >> /home/archiver/archive_out.txt 2>> /home/archiver/archive_err.txt

# List the contents of the processed directory to confirm the log files were successfully moved
ls -l /home/archiver/processed/
- EXPECTED: app1.log, app2.log, and app3.log should be present.

# Display the contents of the raw_logs directory to confirm it is now empty
ls -l /var/tmp/raw_logs/
- EXPECTED: Total 0.

# Check the sizes of the output and error logs using the -s flag to confirm the shell created the files
ls -s /home/archiver/archive_out.txt /home/archiver/archive_err.txt
- EXPECTED: Both files should exist and report 0 blocks, as the find and mv commands succeeded silently.

# Type exit to return to the root shell
exit

4. COMPREHENSIVE CLEANUP (ZERO-TRACE)

# Remove the archiver user and their home directory forcefully using the -r flag
userdel -r archiver

# Recursively remove the temporary raw logs directory using the -r and -f flags to bypass prompts
rm -rf /var/tmp/raw_logs
You should also read:

RHCSA Series (005): Providing User Interfaces

Mind Map RHCSA_Series_5_Providing_User_Interfaces_Mind_Map │ ├── Alphabetical_List_of_Abbreviations │ ├── CLI = Command-Line Interface │ ├── CSCI = Computer Science │ ├── CSH = C…

RHCSA Series (004): Managing Memory

Mind Map RHCSA_Series_4_Managing_Memory_Mind_Map │ ├── Alphabetical_List_of_Abbreviations │ ├── CPU = Central Processing Unit │ ├── cron = Chron Table (scheduler) │ ├── dstat…