The Automated Server Health & Security Audit Tool is an advanced Bash scripting project designed to transform trainees into proficient systems automation engineers. This command-line utility provides a comprehensive, real-time diagnostic of Linux server environments. It systematically monitors critical system metrics, including CPU load, memory utilization, and disk space—while concurrently executing rigorous security audits to detect unauthorized root logins, vulnerable file permissions, and exposed network ports. Built with production-grade standards, the tool features strict execution modes, structured logging, adaptable output formatting (JSON, CSV, Text), and automated webhook alerting. This project bridges the gap between basic scripting and enterprise-ready infrastructure management.
CPU Usage: Current load average and overall CPU utilization percentage.Memory Usage: Total, used, and available RAM. Alert if usage is > 90%.Disk Space: Check all mounted partitions. Alert if any partition is > 80% full.Uptime: How long the system has been running.
Root Logins: Check /var/log/auth.log or /var/log/secure for recent direct root logins.Sudoers: List all users who currently have sudo privileges.Dangerous Permissions: Find any files in /etc or /var/www that have 777 permissions.Open Ports: List all actively listening network ports and their associated services (look into ss or netstat).
-h: Show a well-formatted help/usage menu.-f : Output format. Acceptable values are text (default), csv, or json.-o : Write the output to a specific file instead of the terminal.-q: Quiet mode. Do not print to standard output (useful for cron jobs).
Strict Mode: Your script MUST start with set -euo pipefail.Logging: Every time the script runs, it must log the execution time, the user who ran it, and a summary of any critical alerts to /var/log/sys_audit.log (or a local audit.log if run without root privileges).Graceful Exits: If a required command (like ss or awk) is missing from the system, the script must log an error and exit gracefully, not crash mid-execution.
Advanced CLI Argument Parsing (getopts)
Concept: Handling dynamic user inputs safely using standard POSIX flags (e.g., -f, -o, -q).Application: Building conditional execution paths (like quiet mode or specific output formats) based on runtime arguments, rather than hardcoding variables.Strict Execution Modes (set -euo pipefail)
Concept: Modifying default Bash behavior to fail on uninitialized variables, exit immediately on command failures, and catch errors within piped commands.Application: Preventing runaway scripts that could cause system damage or silently output incorrect data.Complex Text Processing (awk, sed, grep)
Concept: Parsing unstructured or tabular terminal output into clean, usable variables.Application: Extracting specific memory values from free, calculating CPU loads, or pulling specific log entries from /var/log/auth.log without relying on external scripting languages like Python.Defensive Programming & Error Handling
Concept: Anticipating failures (e.g., missing dependencies, permission denied errors) and handling them gracefully using logical OR (|| true), custom exit codes, and fallback defaults.Application: Ensuring the script can scan /etc for 777 files without crashing completely if it hits a single "Permission Denied" directory.Data Serialization (JSON & CSV Formatting)
Concept: Structuring raw strings and integers into machine-readable formats.Application: Building custom JSON payloads string-by-string, handling necessary character escaping (like quotes and newlines) directly within Bash.Process Substitution and File Descriptors
Concept: Redirecting stdout and stderr independently (2>/dev/null, >&2).Application: Keeping terminal output clean for the end-user while still capturing error data internally or logging it to a file.
Enterprise-Grade Logging
Skill: Moving beyond simple echo statements to build structured, timestamped log entries categorizing output by severity (INFO, WARNING, ERROR).Value: Trainees learn how to build tools that leave an auditable trail, which is a hard requirement for tools deployed in enterprise environments.System Health & Performance Monitoring
Skill: Understanding how to interpret core Linux performance metrics (load averages vs. CPU percentage, physical RAM vs. swap).Value: Enhances their foundational Linux System Administration knowledge, making them better troubleshooters.Automated Vulnerability Scanning
Skill: Identifying common misconfigurations such as overly permissive files (777), exposed network sockets (ss, netstat), and unauthorized escalation (sudoers).Value: Introduces trainees to DevSecOps principles and automated compliance auditing.Third-Party API Integration (Webhooks)
Skill: Utilizing curl to construct and send HTTP POST requests with custom headers and JSON payloads.Value: Teaches trainees how to connect isolated terminal tools to modern communication platforms (Slack, Teams, Discord), establishing a foundation for ChatOps and automated alerting.Terminal UI/UX Design
Skill: Utilizing ANSI escape sequences to apply color coding and formatting to terminal output.Value: Teaches trainees that scripts should not only work well but also provide immediate, scannable visual feedback to the operator (e.g., Red for Critical, Green for OK).