Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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 autom +agicaldns entry magic) if [ "$?" == "1" ] ; then # Grab the model name from AD (remember to kinit) MODEL=`/opt/adi/bin/adcat.py -x computer $HOST|grep M +odel|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 nobod +y 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 s +ar -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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Usage gathering query
by apl (Monsignor) on Apr 21, 2008 at 18:27 UTC | |
|
Re: Usage gathering query
by pc88mxer (Vicar) on Apr 21, 2008 at 20:52 UTC |