LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-19-2006, 04:25 PM   #1
koflanagan
LQ Newbie
 
Registered: Mar 2005
Location: San Antonio
Posts: 20

Rep: Reputation: 0
Script to change routes when primary net connection 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
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet Connection Dies patisawsome Linux - Networking 1 02-24-2006 12:34 PM
Linux Web Server - Domain Change and loss of net connection littlered Linux - Networking 3 01-02-2006 10:08 PM
ISDN connection dies phil81 Debian 0 01-05-2005 03:57 AM
net dies all the time shania Linux - Newbie 5 11-11-2003 12:30 AM
idea: sharing net connection, method: iptables..., problem: broken net connection :( danny2055 Linux - Networking 4 06-09-2003 07:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration