function acpu () { if [ "${1:0:2}" == "-h" ]||[ "${1:0:2}" == "-?" ] then echo -e "\033[0;32mReinis ${FUNCNAME[0]} V1.0\033[0m" echo "Reinis .bashrc Tools" echo "" echo -e "\033[1;30;47m${FUNCNAME[0]} IP-Adresse CPU_NR\033[0m" echo "Zeigt CPU-Auslastung von CPU_NR der IP-Adresse" echo "" echo "IP-Adresse default ist localhost" echo "" echo "CPU_NR default ist Durchschnitt aller CPUs" echo "" echo "Default timing = s3, also 3 Sekunden" echo "" echo "Exapmle:" echo -e "\033[1;30;47m${FUNCNAME[0]} 192.168.0.10 4 s5\033[0m" echo "Misst von IP 192.168.0.10 der 4tn CPU alle 5Sekunden" return fi if echo $1 |egrep '.*\..*\..*\..*' >/dev/null 2>&1 then remote=$(echo "ssh $1") cpunr=$(echo "$2") else remote=$(echo "") cpunr=$(echo "$1") fi if [ "$cpunr" == "" ] then cpunr=$(echo "1") else ((cpunr=cpunr+1)) fi timese=$(for x in $*;do echo $x|grep '^s';done) timeset=$(echo ${timese:1:2}) if [ "$timeset" == "" ] then timeset=$(echo "3") fi if [ "$remote" == "" ] then remot=$(echo "localhost") else remot=$(echo "$remote") fi if [ "$cpunr" == "1" ] then cpun=$(echo "Last-Durchschnitt") else ((cpunr=cpunr-1)) cpun=$(echo "CPU_NR $cpunr") fi while : do cpu_now=($($remote head -n$cpunr /proc/stat|tail -n1)) cpu_sum="${cpu_now[@]:1}" cpu_sum=$((${cpu_sum// /+})) cpu_delta=$((cpu_sum - cpu_last_sum)) cpu_idle=$((cpu_now[4]- cpu_last[4])) cpu_used=$((cpu_delta - cpu_idle)) cpu_usage=$(echo|mawk '{OFMT="%.2f";print 100 * '$cpu_used'/'$cpu_delta'}') cpu_last=("${cpu_now[@]}") cpu_last_sum=$cpu_sum echo "Auslastung $cpun von $remot = $cpu_usage%" sleep $timeset if [ $timeset == 0 ] then return fi done }