tcpu - scripts - various script and utils
 (HTM) git clone git://z3bra.org/scripts
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       tcpu (446B)
       ---
            1 #!/bin/sh
            2 #
            3 # z3bra - (c) wtfpl 2014
            4 
            5 usage () {
            6     cat <<EOF
            7 usage: $(basename $0) [-hp]
            8     -h : print help
            9     -p : percentage of cpu used (default)
           10     -n : number of running processes
           11 EOF
           12 }
           13 
           14 cpuperc () {
           15     LINE=`ps -eo pcpu |grep -vE '^\s*(0.0|%CPU)' |tr '\n' '+'|sed 's/+$//'`
           16 
           17     echo "`echo $LINE | bc`%"
           18 }
           19 
           20 cpunumb() {
           21     ls /proc | grep -oE '^[0-9]*$' | wc -w
           22 }
           23 
           24 case $1 in
           25     -h) usage;;
           26     -n) cpunumb;;
           27      *) cpuperc;;
           28 esac