COMP 10024 – Assignment ~ The Automated System Administrator (Week 8)
March 9, 2026 7:27 pmTotal Weight: 3 Points
Objective: Create a robust Bash script that handles user input, validates the file system, and utilizes loops and conditional logic to automate a common administrative task.
The Scenario
You have been hired as a Junior SysAdmin. Your first task is to create a tool called inspector.sh. This tool needs to look at a directory provided by the user and give a “status report” on the files inside. If the user doesn’t provide a directory, the script should be smart enough to ask for one.
Requirements (The Rubric)
Part 1: The Setup & Validation (1 Point)
- Your script must start with the correct sh’bang for the Bash interpreter.
- Include a header comment with your name and the date.
- Logic: Check if a command-line argument was provided (
$1).- If no argument was provided, use
readto ask the user for a directory path. - If the path provided (either via argument or read) is not a directory, print an error message and
exit 1.
- If no argument was provided, use
Part 2: The Inspection Loop (1 Point)
- Once you have a valid directory, use a
forloop to iterate through every item inside that directory. - For each item, use an
if/elifstructure to identify if the item is:- A Regular File (Test with
-f) - A Sub-directory (Test with
-d)
- A Regular File (Test with
- Print the name of the item and its type to the screen.
Part 3: The Summary & Exit (1 Point)
- Keep a running count of how many files and how many directories were found.
- After the loop finished, print a summary: “Inspection Complete: Found X files and Y directories.”
- Exit the script successfully with
exit 0.
Submission Instructions
Before submitting, you must ensure your script is actually “runnable” by the grader:
- Set the permissions using
chmod 755 inspector.sh. - Test it by running
./inspector.sh /etc(or any directory you have access to). - Verify the exit code by running
echo $?immediately after your script finishes.
Starter Template
If you’re stuck, use this as your skeleton:
#!/bin/bash
# Name: [Your Name]
# Date: [Today's Date]
# 1. Capture the directory
DIR=$1
# 2. Check if DIR is empty, if so, read input
if [ -z "$DIR" ]; then
echo -n "Please enter a directory path: "
read DIR
fi
# 3. Check if it's a valid directory
if [ ! -d "$DIR" ]; then
echo "Error: $DIR is not a directory."
exit 1
fi
# ... Your loop and logic goes here ...
Categorised in: COMP-10024, Lectures, Portfolio
This post was written by amax
Comments are closed here.