Skip to content

Instantly share code, notes, and snippets.

@NULLx76
Created February 20, 2016 22:13
Show Gist options
  • Save NULLx76/fd43d7467a8a8104c788 to your computer and use it in GitHub Desktop.
Save NULLx76/fd43d7467a8a8104c788 to your computer and use it in GitHub Desktop.
#!/bin/sh
#
# z3bra - (c) wtfpl 2014
usage () {
cat <<EOF
usage: $(basename $0) [-hp]
-h : print help
-p : percentage of cpu used (default)
-n : number of running processes
EOF
}
cpuperc () {
LINE=`ps -eo pcpu |grep -vE '^\s*(0.0|%CPU)' |tr '\n' '+'|sed 's/+$//'`
echo "`echo $LINE | bc`%"
}
cpunumb() {
ls /proc | grep -oE '^[0-9]*$' | wc -w
}
case $1 in
-h) usage;;
-n) cpunumb;;
*) cpuperc;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment