Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@prestelpirate
Created December 7, 2016 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prestelpirate/ae46a9ae77d971500df5c88038ff47f9 to your computer and use it in GitHub Desktop.
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
#!/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