Fedora Linux Support Community & Resources Center
  #1  
Old 22nd May 2006, 08:11 PM
koflanagan Offline
Registered User
 
Join Date: Mar 2005
Posts: 27
Script to change default route when primary fails

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
Reply With Quote
Reply

Tags
change, default, fails, primary, route, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I need to change the primary prompt bdeklerk Using Fedora 2 13th April 2009 03:34 PM
Change default route sheffrem Servers & Networking 3 20th December 2006 06:17 PM
Primary Moniter change with TwinView? JimmyBlaze Hardware & Laptops 0 27th April 2006 12:45 AM
My wireless card autostarts and fails to set default route Kurush Servers & Networking 2 1st November 2005 06:18 AM


Current GMT-time: 03:44 (Friday, 01-08-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat