RHCSA (043): Season 2 - Scenario 18: Advanced Text Operations
Podcast: The RHCSA Series Podcast
- Season: 2 (Episodes 26A - 50)
- Episode: 43
- Title: RHCSA (043): Season 2 - Scenario 18: Advanced Text Operations
- Release date: November 17, 2026
- Produced by: Djere Services Group
- Associated article: https://djere.com/rhcsa-043-season-2-scenario-18-advanced-text-operations.html
Episode 043 Executive Summary
In this Advanced Text Operations 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. We focus on integrating command-line text processing with user environment configurations to simulate a strict audit requirement.
Administrators often struggle with combining shell variables, input parsing, and strict user security controls. This scenario requires you to establish a secure user environment with a non-standard umask and then parse specific data from a system log, redirecting the formatted output into a protected configuration file. The challenge lies in ensuring that the newly created text file inherits the correct permissions natively from the shell session without manual modification.
To resolve this, you will generate a custom user profile, authenticate as the new user, and execute targeted text stream manipulation using standard shell utilities. By extracting exact fields and formatting them via shell built-ins, you prove your mastery of Domain 1 text tools. Verification involves auditing the final text file to confirm both the parsed content and the restrictive default permissions.
Keywords: shell variables, text processing, umask, user administration, file redirection
EPISODE 043: Advanced Text Operations
* Season: 2 | Difficulty: High
* Objectives: Primary 1.7, 1.1; Secondary 9.1, 10.2
* Lab Focus: shell variables, text processing, umask, user administration, file redirection
* URL: https://djere.com/rhcsa-043-season-2-scenario-18-advanced-text-operations.html
***
1. SCENARIO BRIEF (THE PROBLEM)
A compliance audit requires parsing the system services file to extract a unique list of all TCP-based service names. This operation must be performed by a dedicated service account. Furthermore, strict security policies mandate that any file created by this service account must be completely inaccessible to other users from the moment of creation. You must configure the user environment to enforce this permission structure natively, then use shell tools to process the text and redirect the output.
***
2. TASK ANALYSIS (THE "WHY")
- 1.7 (Text Files): Parsing and extracting specific columns from text streams is a daily operational requirement for isolating data.
- 1.1 (Shell): Utilizing shell variables and pipelining commands enables administrators to build reusable, dynamic administrative workflows.
- 9.1 (Create/Delete/Modify): Dedicated accounts ensure that scheduled tasks and scripts run with the principle of least privilege.
- 10.2 (Umask): Modifying the default file creation mask is the only way to guarantee that sensitive files are born with restrictive permissions.
***
3. SOLUTION STEPS
Step 1: Environment Setup (Root Only)
rpm -q tar || dnf install -y tar
# Copy a system configuration file to a public directory for safe parsing
cp /etc/services /tmp/services-list.txt
# Grant read access to all users so the auditor account can process the file
chmod 644 /tmp/services-list.txt
# Create the service account required for the text processing tasks
useradd -m -s /bin/bash log-auditor
# Set the default permissions for the new user by modifying their profile to enforce a 077 umask
echo "umask 077" >> /home/log-auditor/.bashrc
Step 2: Core Implementation (Execute as log-auditor)
su - log-auditor
# Define a shell variable to hold the target search pattern for the text extraction
SEARCH_PATTERN="tcp"
# Extract lines matching the pattern, isolate the first column containing the service name, sort uniquely, and save to a new file
grep $SEARCH_PATTERN /tmp/services-list.txt | awk '{print $1}' | sort -u > /home/log-auditor/tcp-services.txt
# Technical Breakdown: The grep command filters lines based on the shell variable. The output is piped to awk, which isolates the first field. Finally, sort with the unique flag removes duplicates before redirection.
# Pro-Tip: Be mindful of your shell environment. If you do not switch to the user with a login shell, the bashrc file will not be sourced, and the umask will fail to apply.
Step 3: Verification (The "Proof of Work")
ls -l /home/log-auditor/tcp-services.txt
* EXPECTED: -rw-------. 1 log-auditor log-auditor [size] [date] /home/log-auditor/tcp-services.txt
# Read the first five lines of the output file to confirm text processing success
head -n 5 /home/log-auditor/tcp-services.txt
* EXPECTED: A sorted list of TCP service names.
# Exit the log-auditor shell to return to the root prompt
exit
***
4. COMPREHENSIVE CLEANUP (ZERO-TRACE)
userdel -r log-auditor
# Delete the temporary services file used for the text processing lab
rm -f /tmp/services-list.txt
