#! /bin/bash # script to determine which hosts are free. Launch this script to determind the occupancy of the nodes in the clsuter. issue this in the frontend. percentage=30 ## if cpu usage above percentage, its considered busy ### list of hosts ################ #cat /etc/hosts | awk 'NF==4 {print $4}' | uniq | sort > temp.dat #echo 192.168.1.10 > temp2.dat #cat temp.dat >> temp2.dat #hosts=$(cat temp2.dat | uniq) #rm -rf temp.dat temp2.dat temp2.dat coc-sshreachable hosts=$(cat /share/tmp/ssh-reachable.dat) ### end of list of hosts ######### frontend=$HOSTNAME rm -rf check1.DAT freenodecount=0 for i in $hosts do echo checking $i checkping=$(ping -q -c1 -W 1 $i | awk 'NR==4 {print $4}') if [ $checkping -eq 0 ] then echo $i is not responding after being pinged for 1 second fi if [ $checkping -eq 1 ] then if [ $i != 'c0' ] then #echo checking $i # ssh -X -Y $i 'ps -eo pcpu,pid,user,args | sort -k 1 -r | head -5' | awk 'NR>1{print $1}' > /tmp/temp.dat ssh -X -Y -o ConnectTimeout=5 $i 'ps -eo pcpu,pid,user,args | sort -k 1 -r | head -5' | awk 'NR>1{print $1," ",$3}' > ~/temp2.dat user=$(cat ~/temp2.dat | awk 'NR==1 {print $2}') cat ~/temp2.dat | awk '{print $1}' > ~/temp3.dat cp ~/temp3.dat ~/temp.dat sum=$(awk '{ t += $1 }END{print t}' ~/temp.dat) rm ~/temp.dat ~/temp2.dat ~/temp3.dat int=${sum/\.*} if [ "$int" -gt "$percentage" ]; then echo $i is occupied. cpu usage is $sum '%'. Main user is $user elif [ "$int" -le "$percentage" ]; then freenodecount=$(( $freenodecount + 1 )) echo $i is free. cpu usage is $sum '%'. Main user is $user freenode[$freenodecount]=$i echo 'freenode['$freenodecount'] is ' "${freenode[$freenodecount]}" fi echo ' ' fi fi done echo Free nodes are for (( num=1; num<=$freenodecount; num++ )) do echo "${freenode[$num]}" # echo "${freenode[$num]}" > "${freenode[$num]}" done echo 'Number of compute node free to use is ' $freenodecount