How to Run
chmod +x system_health_check.sh
sudo bash system_health_check.sh
bash system_health_check.sh --log ~/my_health.log
bash system_health_check.sh --no-color
bash system_health_check.sh --host 1.1.1.1
Tip: If run without sudo, the script automatically falls back to saving the log in your home directory (~/system_health.log) instead of crashing.
What Each Section Does Section What it checks Alert condition System Info Hostname, OS, kernel, uptime — CPU Usage Real-time usage via /proc/stat, top 5 processes ⚠ ≥70% · ✘ ≥90% Memory RAM/Swap used vs. total via free -h ⚠ ≥75% · ✘ ≥90% Disk Usage All real partitions via df -h ⚠ any partition ≥80% Network All IPs, gateway, DNS, ping test ✘ if ping fails Services Checks sshd, apache2, nginx, cron, ufw ⚠ if inactive Load Average 1/5/15-minute load from uptime ⚠ if load > core count Key Design Choices
Dual output — every line prints to terminal (with color) and appends clean plain text to the log file simultaneously via a shared $REPORT variable.
Graceful fallbacks — uses /proc/stat instead of fragile top parsing; falls back to /etc/os-release if lsb_release isn't installed; handles missing systemctl.
Timestamped logs — each run appends (not overwrites) to the log with a full timestamp header, so you get a history.
Configurable — threshold, services list, ping host, and log path are all variables at the top, easy to customize.