PHASE 5 · MODULE 4

Bash Scripting & IT Service Management

Master shell scripting fundamentals and understand how ticketing systems manage IT service delivery.

1. Learning Objectives

2. Module Breakdown

⏱️ Duration: ~30 mins 🏷️ Level: Beginner

Module 1: Bash Basics

Introduction to shell interpreters, shebang lines (`#!/bin/bash`), script permissions (`chmod +x`), and basic execution models.

⏱️ Duration: ~30 mins 🏷️ Level: Beginner

Module 2: Variables & Arguments

Working with user-defined variables, positional parameters (`$1`, `$2`, `$#`, `$@`), and environment variables in scripts.

⏱️ Duration: ~40 mins 🏷️ Level: Intermediate

Module 3: Control Structures

Implementing conditional branching using `if/elif/else` statements and `case` selectors for robust input validation.

⏱️ Duration: ~35 mins 🏷️ Level: Intermediate

Module 4: Loops in Practice

Automating batch operations across lists and servers using `for`, `while`, and `until` loops paired with system checks.

⏱️ Duration: ~40 mins 🏷️ Level: Intermediate

Module 5: Text Processing

Extracting, transforming, and summarizing log data with `grep`, stream editing with `sed`, and columnar parsing with `awk`.

⏱️ Duration: ~25 mins 🏷️ Level: Intermediate

Module 6: Cron Jobs

Automating recurring administrative tasks, backups, and health checks using crontab syntax and systemd timers.

⏱️ Duration: ~30 mins 🏷️ Level: Foundational

Module 7: ITIL Fundamentals

Understanding IT Service Management (ITSM), incident life cycles, service desks, and ITIL v4 guiding principles.

⏱️ Duration: ~25 mins 🏷️ Level: Foundational

Module 8: Ticketing Tools Overview

Comparing leading ITSM platforms (Jira Service Management, Freshservice, Zendesk) and exploring core ticketing workflows.

⏱️ Duration: ~25 mins 🏷️ Level: Advanced

Module 9: SLA Management

Defining Service Level Agreements, differentiating response vs. resolution targets, and designing escalation matrices.

3. Module 1: Bash Basics

Bash (Bourne Again SHell) is the standard command interpreter on most Linux distributions and macOS environments. As an IT support professional or systems engineer, writing shell scripts allows you to automate repetitive tasks, standardize environment configurations, and troubleshoot issues rapidly.

The Shebang Line

Every executable shell script begins with a shebang line: #!/bin/bash. This tells the operating system which interpreter binary should be invoked to execute the commands contained within the file.

Creating and Executing Your First Script

To create and run a basic script, follow these standard terminal steps:

# 1. Create the script file using a text editor like nano nano health_check.sh # 2. Add the following content: #!/bin/bash # Description: Simple system health check script echo "==============================" echo "System Health Report: $(date)" echo "==============================" echo "Hostname: $(hostname)" echo "Uptime: $(uptime -p)" echo "------------------------------" # 3. Save and exit, then make the script executable chmod +x health_check.sh # 4. Execute the script ./health_check.sh

4. Module 2: Variables & Arguments

Variables store data values that can be referenced throughout your script. Bash is dynamically typed and treats variables as strings by default.

#!/bin/bash # Declaring and using variables SERVICE_NAME="nginx" LOG_DIR="/var/log/nginx" echo "Checking status of service: ${SERVICE_NAME}" echo "Log directory located at: ${LOG_DIR}"

Positional Parameters

When running scripts from the terminal, you can pass arguments that become available inside the script as positional parameters:

Parameter Description
$0 The filename of the current script.
$1 - $9 The first through ninth positional arguments passed to the script.
$# The total number of positional arguments passed.
$@ All positional arguments as separate strings.
$? The exit status of the last executed command (0 for success, non-zero for failure).
#!/bin/bash # script_args.sh echo "Script name: $0" echo "Total arguments passed: $#" echo "First argument (User): $1" echo "Second argument (Department): $2"

5. Module 3: Control Structures

Control structures allow your scripts to make decisions based on test conditions, file statuses, or numerical comparisons.

#!/bin/bash # Checking disk space threshold THRESHOLD=85 CURRENT_USAGE=$(df / | grep / | awk '{print $5}' | sed 's/%//') if [ "$CURRENT_USAGE" -gt "$THRESHOLD" ]; then echo "WARNING: Disk usage is critically high at ${CURRENT_USAGE}%!" # Trigger alert or notification here else echo "OK: Disk usage is normal at ${CURRENT_USAGE}%." fi

Case Statements

When handling multiple discrete options (such as service management menus), `case` statements provide cleaner syntax than chained `if/elif` blocks.

#!/bin/bash case "$1" in start) echo "Starting IT support daemon..." systemctl start itsupport ;; stop) echo "Stopping IT support daemon..." systemctl stop itsupport ;; status) systemctl status itsupport ;; *) echo "Usage: $0 {start|stop|status}" exit 1 ;; esac

6. Module 4: Loops in Practice

Loops automate repetitive execution blocks. In IT administration, loops are frequently used to iterate through lists of IP addresses, server names, or log files.

#!/bin/bash # For loop iterating over server list SERVERS=("web-01" "db-01" "cache-01") for server in "${SERVERS[@]}"; do echo "Pinging ${server}..." ping -c 1 "${server}" &> /dev/null if [ $? -eq 0 ]; then echo " [SUCCESS] ${server} is online." else echo " [ALERT] ${server} is unreachable!" fi done

While Loops for Service Polling

#!/bin/bash # Polling a service until it responds PORT=8080 echo "Waiting for service on port ${PORT} to come online..." while ! nc -z localhost "${PORT}"; do sleep 2 done echo "Service is now online and accepting connections!"

7. Module 5: Text Processing

Text processing utilities form the backbone of log parsing and data extraction in Linux environments.

Grep & Sed

grep: Searches input files for lines matching a regular expression pattern.
grep -i "error" /var/log/syslog

sed: Stream editor used for filtering and transforming text in pipelines.
sed 's/old_ip/new_ip/g' config.conf

Awk & Sort/Uniq

awk: Pattern scanning and processing language designed for columnar data.
awk '{print $1, $9}' access.log

sort & uniq: Ordering data and filtering or counting duplicate occurrences.
sort error.log | uniq -c | sort -nr

8. Module 6: Cron Jobs

Cron is a time-based job scheduler in Unix-like operating systems. Automated administrative scripts are routinely triggered via crontab entries.

Field Allowed Values Description
Minute 0 - 59 Minute of the hour when the job runs
Hour 0 - 23 Hour of the day in 24-hour format
Day of Month 1 - 31 Calendar day of the month
Month 1 - 12 or JAN-DEC Calendar month
Day of Week 0 - 6 or SUN-SAT Day of the week (0 = Sunday)
# Example Crontab Entries # Edit crontab using: crontab -e # Run disk cleanup script every day at 2:30 AM 30 2 * * * /usr/local/bin/cleanup_temp.sh >> /var/log/cleanup.log 2>&1 # Run weekly system update check every Monday at 4:00 AM 0 4 * * 1 /usr/local/bin/weekly_audit.sh

9. Module 7: ITIL Fundamentals

Information Technology Infrastructure Library (ITIL) is the most widely accepted framework for IT Service Management (ITSM). It provides structured guidance on aligning IT services with business needs.

The IT Incident Life Cycle

New → Assigned → In Progress → Pending (Optional) → Resolved → Closed
Every support ticket moves through a defined lifecycle. Accurate status tracking ensures accountability, metrics reporting, and timely closure.

Incident Priority Matrix

Priority Impact Urgency Target Response Target Resolution
P1 - Critical Organization-wide Immediate 15 Minutes 4 Hours
P2 - High Department / Multiple Users High 1 Hour 8 Hours
P3 - Medium Single User Medium 4 Hours 24 Hours
P4 - Low Inconvenience / Request Low 8 Hours 72 Hours

10. Module 8: Ticketing Tools Overview

Enterprise ITSM platforms centralize user requests, incident management, asset tracking, and knowledge bases.

Platform Key Strengths Best Suited For
Jira Service Management Deep developer integration, agile workflows, automation rules, asset management. Tech-heavy organizations & software engineering teams.
Freshservice Intuitive UI, robust IT asset discovery, strong SLA management, gamification. Mid-market enterprises seeking fast deployment.
Zendesk Omnichannel support (chat, email, voice), extensive marketplace apps, customer portal. Customer-facing support and large helpdesks.

11. Module 9: SLA Management

Service Level Agreements (SLAs) are formal commitments between an IT service provider and the business defining expected service standards.

Response Time SLA

The time window within which a support technician must acknowledge receipt of the ticket, assign an owner, and make initial contact with the user.

Resolution Time SLA

The total elapsed time from ticket creation until the underlying issue is fully mitigated or resolved to the user's satisfaction.

12. Hands-on Labs

Lab 1: Automated Disk Usage Monitoring Script

Write a Bash script that checks root partition usage, logs a timestamped warning to /var/log/disk_monitor.log if usage exceeds 80%, and outputs status.

Show Solution
#!/bin/bash LOG_FILE="/var/log/disk_monitor.log" USAGE=$(df / | grep / | awk '{print $5}' | tr -d '%') if [ "$USAGE" -ge 80 ]; then echo "$(date): CRITICAL - Disk usage at ${USAGE}%" >> "$LOG_FILE" else echo "$(date): INFO - Disk usage normal at ${USAGE}%" >> "$LOG_FILE" fi

Lab 2: Cron Job Configuration

Configure a crontab entry that executes your disk monitoring script every hour on the minute zero.

Show Solution
# Run every hour 0 * * * * /usr/local/bin/disk_monitor.sh

Lab 3: Incident Report Parser

Use awk and grep to parse a system log file and output a count of all unique error messages.

Show Solution
#!/bin/bash grep "ERROR" /var/log/syslog | awk '{print $5, $6, $7}' | sort | uniq -c

13. Code Reference Tables

Command / Operator Category Description
[ -f file ] Conditional Test Returns true if file exists and is a regular file.
[ -d dir ] Conditional Test Returns true if directory exists.
-eq, -ne, -gt, -lt Numerical Comparison Equal, not equal, greater than, less than.
=, != String Comparison String equality and inequality tests.
>> Redirection Append stdout to a file without overwriting.
2>&1 Redirection Redirect standard error to standard output.

14. Knowledge Check

1. What is the standard purpose of the shebang line (#!/bin/bash) at the top of a script?
It specifies the absolute path of the interpreter binary that the operating system should use to execute the script.
2. Which positional parameter represents the total number of arguments passed to a Bash script?
$# represents the total count of positional parameters.
3. In cron syntax, what does an asterisk (*) in the first field represent?
Every minute (minute 0 through 59).
4. What is the primary difference between a Response SLA and a Resolution SLA?
Response SLA measures the time until initial technician acknowledgement/contact, whereas Resolution SLA measures the total time until the issue is fully fixed.
5. Which text processing utility is best suited for columnar data extraction (e.g., printing specific fields)?
awk is designed specifically for pattern scanning and columnar data extraction.

15. Resources

16. Progress Checklist

17. Next Steps

Proceed to Phase 6 — Career Prep to finalize your IT support portfolio, resume preparation, and interview readiness.

← Previous: PowerShell Scripting Next: Career Prep →