|
12345678910111213141516171819202122232425262728 |
- #!/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)' |sed -n '1h;$!H;$g;s/\n/ +/gp'`
-
- echo "`echo $LINE | bc`%"
- }
-
- cpunumb() {
- ls /proc | grep -oE '^[0-9]*$' | wc -w
- }
-
- case $1 in
- -h) usage;;
- -n) cpunumb;;
- *) cpuperc;;
- esac
|