Skip to content

Instantly share code, notes, and snippets.

@prestelpirate
Last active December 7, 2016 12:18
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/4b04dfd21dd4f3851853dcf59363009e to your computer and use it in GitHub Desktop.
Save prestelpirate/4b04dfd21dd4f3851853dcf59363009e to your computer and use it in GitHub Desktop.
Before IP MultiPathing (IPMP) came along in Solaris 8, it was difficult to have 2 ethernet interfaces connecting your host to the same LAN in a failover configuration. This script pings a highly-available source (usually your default router or switch) and calls ifconfig to down an interface and up the spare if the ping fails. Your two interfaces…
#!/bin/sh
#
# See http://www.gaeltd.com/scripts-and-tools/ for more details
#
# 2001-01-30 Tom Kranz (tom@siliconbunny.com)
#
# This script is distributed under the GNU Public License (GPL) with the
# following extra conditions:
# - attritbution must be maintained
# - CD-ROM or similar media for commercial distribution without the prior
# approval of the author
# <sigh> I'm being neat and tidy. We return the following error codes:
# 0 - network connectivity is OK as it as - apart from annoyingly printing
# Woohoo nothing has happened
# 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
#
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
if /usr/sbin/ping $1
then
echo "Woohoo!"
exit 0
else
upif="`/usr/sbin/ifconfig -a | grep -v LOOPBACK | grep UP | cut -b 1-4`"
downif="`/usr/sbin/ifconfig -a | grep -v LOOPBACK | grep -v UP | grep RUNNING | cut -b 1-4`"
/usr/sbin/ifconfig $upif down
/usr/sbin/ifconfig $downif up
fi
/usr/sbin/ping $1
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment