[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bash script: set variables, white loops, if statement



 
    
bash script: set variables, white loops, if statement


#!/usr/local/bin/bash

## this script do the regular radius check (on matrix and cassius)
## if one of them failed to response, script check the backup radius
## on mirach. 

## webraft uses this script to switch radius settings

## initialed by Terrence Miao (2001-02-21) 

## how many times after checking we reckon radius server is really down
declare -i loops=3 i=1 j=1
# echo "loops = $loops"
# echo "i = $i"
# echo "j = $j"

## how many seconds should wait if one radius check failed
sleeptime=60
# echo $sleeptime

while [ $i -le $loops ] ; do
	## check student radius server on cassius
	## check staff radius server on matrix
	if /usr/local/web/src/radius/src/radcheck -d /usr/local/web/src/radius/raddb/ cassius >& /dev/null && /usr/local/web/src/radius/src/radcheck -d /usr/local/web/src/radius/raddb/ claret >& /dev/null
	then
		echo "Radius servers on matrix and cassius are OK"
		exit 0
	else
		## check backup server is OK
		while [ $j -le $loops ] ; do
			if /usr/local/web/src/radius/src/radcheck -d /usr/local/web/src/radius/raddb/ mirach >& /dev/null 
			then
				echo "Switching to radius backup server on mirach..."
				exit 1
			else
				let j = $j + 1
				# echo "j = $j"
	
				sleep $sleeptime
			fi
		done

		echo "Primary and backup radius servers are all down!!!"
		exit 1
	fi

	let i = $i + 1
	# echo "i = $i"

	sleep $sleeptime
done

Google