-
-
Save NULLx76/fd43d7467a8a8104c788 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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