Skip to content

Instantly share code, notes, and snippets.

@odino
Created September 9, 2011 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odino/1206034 to your computer and use it in GitHub Desktop.
Save odino/1206034 to your computer and use it in GitHub Desktop.
#!/bin/bash
# ./cpu 80
while true; do eval $(awk '/^cpu /{print "idle=" $5 "; total=" $2+$3+$4+$5 }' /proc/stat); intervaltotal=$((total-${prevtotal:-0}));
CPU="$((100*( (intervaltotal) - ($idle-${previdle:-0}) ) / (intervaltotal) ))";
if [ $CPU -gt $1 ]; then
echo "$CPU";
fi;
previdle=$idle;
prevtotal=$total;
sleep 0.1;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment