1#!/bin/sh 2 3################################################################################ 4## ## 5## Copyright (c) International Business Machines Corp., 2005 ## 6## ## 7## This program is free software; you can redistribute it and#or modify ## 8## it under the terms of the GNU General Public License as published by ## 9## the Free Software Foundation; either version 2 of the License, or ## 10## (at your option) any later version. ## 11## ## 12## This program is distributed in the hope that it will be useful, but ## 13## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ## 14## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ## 15## for more details. ## 16## ## 17## You should have received a copy of the GNU General Public License ## 18## along with this program; if not, write to the Free Software ## 19## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## 20## ## 21## ## 22################################################################################ 23# 24# File: 25# check_icmpv4_connectivity 26# 27# Description: 28# Check the ICMPv4 connectivity from a interface to an IPv4 address 29# 30# Arguments: 31# $1: source interface name 32# $2: destination IPv4 address 33# 34# Returns: 35# 0: connectivity is good 36# 1: connectivity is someting wrong 37# 38# Author: 39# Mitsuru Chinen <mitch@jp.ibm.com> 40# 41# History: 42# Oct 19 2005 - Created (Mitsuru Chinen) 43# 44#----------------------------------------------------------------------- 45#Uncomment line below for debug output. 46#trace_logic=${trace_logic:-"set -x"} 47$trace_logic 48 49# The max number of ICMP echo request 50PING_MAX=10 51 52# Check the arguments 53if [ $# -ne 2 ]; then 54 echo "Usage: $0 source_interface_name destionation_ipv4_address" >&2 55 exit 1 56fi 57src_ifname=$1 58dst_ipv4addr=$2 59 60cnt=0 61while [ $cnt -lt $PING_MAX ]; do 62 cnt=`expr $cnt + 1` 63 ping -I $src_ifname -c 1 $dst_ipv4addr -w 1 > /dev/null 2>&1 64 if [ $? -eq 0 ]; then 65 exit 0 66 fi 67 sleep 1 68done 69 70exit 1 71