#!/bin/bash # # Displays details of loading and the user's own # running processes on a list of hosts. # Find the directory containing this script. basedir="$(dirname "$(realpath "$0" )" )" # Get the list of hostnames: source "$basedir/hosts.list" echo " " declare -a names n=0 names=("" `echo "$usehosts" | cut -d, -f1 | xargs`) nhosts="`echo "$usehosts" | wc -l`" for n in `seq 1 $nhosts` do echo "login $n: ${names[$n]}" tmpy="` ssh ${names[n]} ps -eo user,pcpu,rss `" psout[n]="` echo "$tmpy" | fgrep -v '%CPU' | sed -e 's/\.[0-9]*//g' `" allcpu[n]="` echo "${psout[n]}" | awk '{ print $2 }' `" mycpu[n]="` echo "${psout[n]}" | grep "^$USER[\t ]" | awk '{ print $2 }' `" allcpusum[n]="$(( 0`echo "${allcpu[n]}" | xargs -n1 | sed -e 's/^/+/' | xargs`+0 ))" mycpusum[n]="$(( 0`echo "${mycpu[n]}" | xargs -n1 | sed -e 's/^/+/' | xargs`+0 ))" allrss[n]="` echo "${psout[n]}" | awk '{ print $3 }' `" myrss[n]="` echo "${psout[n]}" | grep "^$USER[\t ]" | awk '{ print $3 }' `" allrsssum[n]="$(( 0`echo "${allrss[n]}" | xargs -n1 | sed -e 's/^/+/' | xargs`+0 ))" myrsssum[n]="$(( 0`echo "${myrss[n]}" | xargs -n1 | sed -e 's/^/+/' | xargs`+0 ))" done echo " " echo ' HOST mycpu%, allcpu% myrssMB, allrssMB' for n in `seq 1 $nhosts` do printf "%10s: %3d, %3d %5d, %5d\n" ${names[n]} \ ${mycpusum[n]} ${allcpusum[n]} \ $((myrsssum[n]/1024)) $((allrsssum[n]/1024)) done echo " " echo "(note: the ps command and ssh login account for a few MB)" echo " "