Introduction: This script monitors system health by checking CPU usage, memory, and disk space on Linux servers. It can be used to quickly assess the overall performance of your system.
Instructions:
1. Save the script as
.
2. Make it executable using
.
3. Run the script by typing
in your terminal.
Example Output:
Bash:
#!/bin/bash
# System Health Monitor
cpu_usage=$(top -bn1 | grep 'Cpu(s)' | \
sed 's/.*, *\([0-9.]*\)%* id.*/\1/' | \
awk '{print 100 - $1"%"}')
mem_usage=$(free -m | awk 'NR==2{printf "%s/%sMB", $3,$2 }')
disk_usage=$(df -h | awk '$NF=="/"{printf "%d/%dGB", $3,$2}')
echo "CPU Usage: $cpu_usage"
echo "Memory Usage: $mem_usage"
echo "Disk Usage: $disk_usage"
Instructions:
1. Save the script as
Code:
system_health.sh
2. Make it executable using
Code:
chmod +x system_health.sh
3. Run the script by typing
Code:
./system_health.sh
Example Output:
Code:
CPU Usage: 15.3%
Memory Usage: 2048/4096MB
Disk Usage: 40/100GB