Last active
December 7, 2016 12:18
-
-
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…
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 | |
# | |
# 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