Created
December 7, 2016 12:16
-
-
Save prestelpirate/ae46a9ae77d971500df5c88038ff47f9 to your computer and use it in GitHub Desktop.
Ported from an original script written for Solaris 2.6 Provides basic failover between two network interfaces on your IRIX host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# See http://www.gaeltd.com/scripts-and-tools/ for more details | |
# | |
# 2004-09-14 Tom Kranz <tom@siliconbunny.com> | |
# | |
# Ported from an original script written for Solaris 2.6 | |
# Provides basic failover between two network interfaces on your IRIX host | |
# | |
# Pre-reqs: | |
# - you have two ethernet interfaces which use seperate switches | |
# - you have a redundant network point (ie. a default router) | |
# | |
# Setup: | |
# - configure your two ethernet interfaces with the same IP, but | |
# make sure only one is up | |
# - run this script from cron | |
# - cron interval dictates how long you want the host down for | |
# - the script will work out which interface is up and which is down | |
# | |
# Error codes: | |
# 0 - network connectivity is OK | |
# 1 - something's fubar on the network, and we've had to swap interfaces | |
# 2 - you didn't enter a IP address to ping to test connectivity - we'll | |
# print a nice error message and then leave | |
# Static vars | |
PING=/usr/etc/ping | |
IFCONFIG=/usr/sbin/ifconfig | |
# Have you specified an IP to test against? | |
if [ $# -ne 1 ] | |
then | |
echo | |
echo "Usage: if_checker.sh <IP_address_to_ping>" | |
echo | |
echo "Where <IP_address_to_ping> is an always-reachable address you can" | |
echo "use to verify connectivity" | |
echo | |
exit 2 | |
fi | |
# Do the actual test | |
if $PING $1 | |
then | |
echo "Woohoo!" | |
exit 0 | |
else | |
UPIF="`$IFCONFIG -a | grep -v LOOPBACK | grep UP | cut -b 1-4`" | |
$DOWNIF="`$IFCONFIG -a | grep -v LOOPBACK | grep -v UP | grep RUNNING | cut -b 1-4`" | |
$IFCONFIG $UPIF down | |
$IFCONFIG $DOWNIF up | |
fi | |
# Another final ping check to see if the new interface is OK | |
$PING $1 | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment