#!/bin/bash # System Inspection Script # Creates a detailed but sanitized report of system configuration OUTPUT_DIR="system_inspection_$(date +%Y%m%d_%H%M%S)" REPORT_FILE="$OUTPUT_DIR/system_report.txt" # Create output directory mkdir -p "$OUTPUT_DIR" # Helper function for section headers print_section() { echo -e "\n=== $1 ===" | tee -a "$REPORT_FILE" } # Helper function to safely execute commands safe_exec() { local cmd="$1" local desc="$2" print_section "$desc" echo "$ $cmd" >> "$REPORT_FILE" if ! eval "$cmd" >> "$REPORT_FILE" 2>&1; then echo "Command failed or not available" >> "$REPORT_FILE" fi } # Start report echo "System Inspection Report" > "$REPORT_FILE" echo "Generated on: $(date)" >> "$REPORT_FILE" echo "----------------------------------------" >> "$REPORT_FILE" # Basic System Information safe_exec "uname -a" "Kernel Information" safe_exec "lsb_release -a" "OS Information" safe_exec "cat /proc/cpuinfo | grep 'model name' | uniq" "CPU Model" safe_exec "free -h" "Memory Information" safe_exec "df -h" "Disk Usage" safe_exec "uptime" "System Uptime" # Network Configuration print_section "Network Configuration" safe_exec "ip addr | grep -v ether" "Network Interfaces" safe_exec "netstat -tulpn | grep LISTEN" "Listening Ports" safe_exec "cat /etc/hosts" "Hosts File" # Installed Packages print_section "Package Information" safe_exec "dpkg -l | grep -E 'kubernetes|docker|containerd|kubelet|kubeadm|kubectl'" "Relevant Packages" # Service Status print_section "Service Status" safe_exec "systemctl list-units --type=service --state=running" "Running Services" # Docker Status (if installed) print_section "Docker Status" safe_exec "which docker && docker info" "Docker Information" safe_exec "docker ps" "Running Containers" # Kubernetes Status (if installed) print_section "Kubernetes Status" safe_exec "which kubectl && kubectl version" "Kubernetes Version" safe_exec "kubectl get nodes" "Kubernetes Nodes" safe_exec "kubectl get pods --all-namespaces" "Kubernetes Pods" safe_exec "kubectl get services --all-namespaces" "Kubernetes Services" # Security Configuration print_section "Security Configuration" safe_exec "ufw status" "Firewall Status" safe_exec "systemctl status fail2ban" "Fail2ban Status" # Process Information print_section "Process Information" safe_exec "ps aux | grep -E 'docker|kube|containerd'" "Relevant Processes" # System Logs Overview print_section "Recent System Events" safe_exec "journalctl -n 50 --no-pager" "Last 50 System Log Entries" # Resource Usage print_section "Resource Usage" safe_exec "top -b -n 1" "Current Resource Usage" # Mounted Volumes print_section "Mounted Volumes" safe_exec "mount | grep -E 'ext4|xfs'" "Mounted Filesystems" # Network Routes print_section "Network Routes" safe_exec "ip route" "IP Routes" # Create a compressed archive of the report tar -czf "$OUTPUT_DIR.tar.gz" "$OUTPUT_DIR" echo "Inspection complete. Results are in $OUTPUT_DIR/" echo "Compressed archive created: $OUTPUT_DIR.tar.gz" Save it to a file (e.g., `inspect_system.sh`) 2. Make it executable: `chmod +x inspect_system.sh` 3. Run it: `sudo ./inspect_system.sh` The script will: - Create a detailed report of your system - Organize information into clear sections - Save everything to a timestamped directory - Create a compressed archive for easy sharing