fintanr's weblog

Archives

« February 2005 »
MonTueWedThuFriSatSun
 
2
5
6
7
8
9
10
11
12
13
14
16
18
19
21
22
23
24
26
28
      
       
Today

the links




Twitter Updates

    follow me on Twitter
















    20050204 Friday February 04, 2005

    Timeouts at 20 paces....
    A quick bit of shell for checking if machines are alive..... I had to modify a script we use for running a benchmark yesterday to let us know if the client and database tiers had failed to come back up (there was a bit of re wiring work going on in the lab and we lost a rig without realising for a little while due to a disconnected cable). Anyway, a very simple piece of ksh was suffice, but just in case anyone needs something similar....

    
    COUNT=0
    SERVER_UP=0
    
    function CheckServerUp {
    
    	SERVER=$1
    	COUNT_TIMEOUT=$2
    
    	while [ $SERVER_UP -eq 0 -a $COUNT -lt $COUNT_TIMEOUT ]
    	do
    		if [ `ping ${SERVER}| grep alive | wc -l` -eq 1 ]
    		then
    			SERVER_UP=1
    			echo "SERVER ${SERVER} is alive"
    		else
    			echo "Waiting on SERVER ${SERVER} to boot"
    			let COUNT=COUNT+1
    			sleep 60
    		fi
    	done
    }
    
    You just call it as
    CheckServerUp yourServer no_of_times_to_try
    
    i.e.
             CheckServerUp myDB 20
    
    And then just check against your SERVER_UP value to see if you need to do something.
    (2005-02-03 22:31:07.0) Permalink Comments [0]