Skip to content

Instantly share code, notes, and snippets.

@pyropeter
Created July 10, 2010 12:40
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyropeter/470688 to your computer and use it in GitHub Desktop.
Save pyropeter/470688 to your computer and use it in GitHub Desktop.
Simple system monitor
#!/bin/bash
interval=5
intervalLong=300
function getSensors {
sensors | awk 'BEGIN {FS=":? +"} /^Core|^fan[12]|^temp/ {printf "%9s %9s\n", $1, $2}'
}
function getDiskfree {
df -hP | sort -rnk5 | awk '/[89][0-9]%|100%/ {printf "%9s %9s %s\n", $4, $5, $6}'
}
function getHddtemp {
hddtemp /dev/sda /dev/sdb | awk 'BEGIN {FS=": "} // {printf "%9s %9s %s\n", $1, $3, $2}' 2>/dev/null
}
function outRefresh {
echo -e "\n\n\n\n\n\n\n\n\n\n\n"
echo "$outSensors"
echo
echo "$outDiskfree"
if [ ${#outHddtemp} -gt 0 ]; then
echo
echo "$outHddtemp"
fi
echo
echo -n "$(uptime)"
}
function trapInt {
outSensors=$(getSensors)
outDiskfree=$(getDiskfree)
outHddtemp=$(getHddtemp)
outRefresh
echo -ne "\nPress ^C again quickly to quit"
trap SIGINT
sleep 1
trap trapInt SIGINT
}
trap trapInt SIGINT
while true; do
outDiskfree=$(getDiskfree)
outHddtemp=$(getHddtemp)
for (( i=0 ; i<$(($intervalLong/$interval + 1)) ; i++ )); do
outSensors=$(getSensors)
outRefresh
sleep $interval
done
done
Core 0 +43.0°C
Core 1 +43.0°C
fan1 1371 RPM
fan2 1110 RPM
temp1 +36.0°C
temp2 +43.0°C
temp3 +83.0°C
1.7G 99% /mnt/datenhalde
1.3G 97% /mnt/deb-home
8.0G 96% /mnt/gralde2
11G 80% /home
32G 80% /mnt/gralde4
/dev/sda 38°C WDC WD3200AAKS-00L9A0
/dev/sdb 39°C WDC WD5000AADS-00M2B0
10:25:01 up 6 days, 10:46, 29 users, load average: 0.02, 0.01, 0.00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment