for HOST in `cat /tmp/hosts` do MODEL="" USER="" IDLE="" RELEASE="" host $HOST |grep "not found">>/dev/null #Check if the host is switched on and in DNS (due to our automagicaldns entry magic) if [ "$?" == "1" ] ; then # Grab the model name from AD (remember to kinit) MODEL=`/opt/adi/bin/adcat.py -x computer $HOST|grep Model|awk '{print $3}'` # ssh into the box, pick through the last entries, see if a user logged into the console rather than via ssh # if so then thats probably the primary user, if nobody logged in then we're SOL. USER=`ssh $HOST "last|grep ':0\ '|awk '{print \\$1}'|head -n1" 2>/dev/null` if [ "x$USER" == "x" ] ; then USER="NO-LOCAL" fi IDLE="0" AVERAGE="0" SUM="0" NUM="0" # SSH into the box, for each sar entry display the cpu usage and average it for IDLE in `ssh $HOST 'for i in /var/log/sa/sa*; do sar -f $i 2>/dev/null; done' 2>/dev/null|awk '{print $7}'|grep -v idle|sed -e s/...$// ` do SUM=$[$SUM + $IDLE] NUM=$[$NUM + 1] done AVERAGE=$[$SUM / $NUM] RELEASE=`ssh $HOST "uname -r" 2>/dev/null` fi echo "$HOST $MODEL $USER $IDLE $RELEASE" done