Skip to content

Instantly share code, notes, and snippets.

@piaoger
Last active October 26, 2016 08:48
Show Gist options
  • Save piaoger/2d8954f7bed14b2f1c29920950210f1b to your computer and use it in GitHub Desktop.
Save piaoger/2d8954f7bed14b2f1c29920950210f1b to your computer and use it in GitHub Desktop.
query cpu/ram/hdd usage
#!/bin/bash
# from http://unix.stackexchange.com/questions/69167/bash-script-that-print-cpu-usage-diskusage-ram-usage
FREE_DATA=`free -m | grep Mem`
CURRENT=`echo $FREE_DATA | cut -f3 -d' '`
TOTAL=`echo $FREE_DATA | cut -f2 -d' '`
echo CPU: `top -b -n1 | grep "Cpu(s)" | awk '{print $2 + $4}'`%
echo RAM: $(echo "scale = 2; $CURRENT/$TOTAL*100" | bc)%
echo HDD: `df -lh | awk '{if ($6 == "/") { print $5 }}' | head -1 | cut -d'%' -f1`%
# list all disks
echo HDD: `lsblk | grep disk`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment