script to change default route when primary gateway dies

Hello all!

We have two fedora routers one at each site. What we are trying to do worked using freesco but not on fedora, i'm not very good at scripting and need a little guidence. Basicly what we are trying to do is if the primary line dies, the router will change it's routes to go through our t1 line. Here's the script and i'm getting an error saying "syntax error near unexpected token `{ `initial_routes() {"

######################################################
# File Name: san_gw_switch.sh
# Author : XXXXXXXXXXX
# Date : 2/21/2006
# Company : XXXXXXXXXXX
######################################################
#
# Script Parameters
#
PRIMARY="192.168.100.57"
SECONDARY="192.168.100.49"
PRIMARY_GW="192.168.100.42"
SECONDARY_GW="192.168.100.54"
email="helpdesk@########.com"
PINGOUTPUT="/scripts/logs/pingout.txt"
ROUTEOUTPUT="/scripts/logs/routeout.txt"
logfile="/scripts/logs/pinghost.log"
#logfile="/dev/null 2>&1"
sleepcount=3 # sleep 3 seconds
opt="p" # ping initial Primary GW
echo "`date` - Gateway monitoring started..." > ${logfile}
#
#
#######################################################
initial_routes() {
/sbin/route add -net 192.168.253.240 gw 170.231.56.232 netmask 255.255.255.240 dev eth2
/sbin/route add -net 192.168.2.0 gw 10.1.0.2 netmask 255.255.255.0 dev eth2
/sbin/route add -net 192.168.99.0 gw 10.1.1.62 netmask 255.255.255.224 dev eth2
/sbin/route add -net 2.0.160.0 gw 10.1.1.66 netmask 255.255.255.0 dev eth2
/sbin/route add -net 10.145.0.0 gw 192.168.100.42 netmask 255.255.0.0 dev eth1
/bin/route add -net 192.168.100.36 gw 192.168.100.54 netmask 255.255.255.252 dev eth3
/sbin/route add -net 192.168.100.48 gw 192.168.100.42 netmask 255.255.255.252 dev eth1
/sbin/ifconfig eth2:0 inet 170.231.56.1 netmask 255.255.255.0 broadcast 170.231.56.255
}
chg_route_primary() {
/sbin/route del 192.168.100.48
/sbin/route del 10.145.0.0
/sbin/route add -net 192.168.100.48 gw ${PRIMARY_GW} netmask 255.255.255.252 dev eth1
/sbin/route add -net 10.145.0.0 gw ${PRIMARY_GW} netmask 255.255.0.0 dev eth1
/sbin/route -n > ${ROUTEOUTPUT}
cat ${ROUTEOUTPUT}
}
chg_route_secondary() {
/sbin/route del 192.168.100.48
/sbin/route del 10.145.0.0
/sbin/route add -net 192.168.100.48 gw ${SECONDARY_GW} netmask 255.255.255.252 dev eth3
/sbin/route add -net 10.145.0.0 gw ${SECONDARY_GW} netmask 255.255.0.0 dev eth3
/sbin/route -n > ${ROUTEOUTPUT}
cat ${ROUTEOUTPUT}
}
run_primary() {
/bin/ping -c 3 -i 3 $PRIMARY > ${PINGOUTPUT}
if [ "`sed -n /100%/p ${PINGOUTPUT}`" ]; then
echo "`date`" >> ${logfile}
echo " - Primary GW failure on: ${PRIMARY}" >> ${logfile}
echo " - Switching to secondary GW on: ${SECONDARY}" >> ${logfile}
### /bin/mailx -s "Switched to Secondary IP Address ${SECONDARY}" ${email} < /bin/date
opt="s" # setting to Secondary IP Address
chg_route_secondary
else
echo "...Success - Primary GW active on: ${PRIMARY}" >> ${logfile}
fi
} # End of function run_primary
#
#######################################################
re_check_primary() {
/bin/ping -c 3 -i 3 $PRIMARY > ${PINGOUTPUT}
if [ "`sed -n /100%/p ${PINGOUTPUT}`" ]; then
opt="s"
else
echo "`date`" >> ${logfile}
echo " - Primary GW recheck successful, switching back to primary on: ${PRIMARY}" >> ${logfile}
opt="p"
chg_route_primary
fi
} # End of function re_check_primary
#
#######################################################
run_secondary() {
/bin/ping -c 3 -i 3 $SECONDARY > ${PINGOUTPUT}
if [ "`sed -n /100%/p ${PINGOUTPUT}`" ]; then
echo "`date` - OVERALL FAILURE - Primary on: ${PRIMARY} and Secondary on: ${SECONDARY} are not responding!!!" >> ${logfile}
### /bin/mailx -s "Failed to find Primary ${PRIMARY} and Secondary ${SECONDARY} IP Addresses" $email} < /bin/date
opt="f" # setting to fail-fail option
# reset route back to primary
else
echo "`date`" >> ${logfile}
echo " - Failover Success - Secondary GW active on: ${SECONDARY}" >> ${logfile}
re_check_primary
fi
} # End of function run_secondary
#
#######################################################
#######################################################
# Main Script
#######################################################
initial_routes
while [ $opt != n ];
do
case $opt in
p) echo "OPTION: P" >> ${logfile}
sleep ${sleepcount} # waits x seconds
echo "Running primary check."
run_primary;;
s) echo "OPTION: S" >> ${logfile}
sleep ${sleepcount} # waits x seconds
echo "Running secondary check."
run_secondary;;
f) echo "OPTION: FAIL - Cannot Access Primary ${PRIMARY} or Secondary ${SECONDARY}" >> ${logfile}
###/bin/mailx -s "Cannot Access Primary $PRIMARY} and Secondary ${SECONDARY} IP Addresses" ${email} < /bin/date
echo "All routes failed!!!"
run_secondary;;
esac
done
#

We had this working on two freesco boxes, but those became a little unstable. We were having issues with freesco seeing or detecting nics and keeping the virtual nic. If anyone can post a link or anything it would be greatly appreciated.

Kevin