Create a Post
cancel
Showing results for 
Search instead for 
Did you mean: 
Ivan_Moore
Contributor

Ping Gateway Script

Whenever we do any work on a gateway we have to do various health checks especially when rebooting a gateway.   One simple check that is important is pinging the next hop gateways.  We do this before and after a change to make sure that something didn't break such as an interface going into error disabled on a switch...which tends to happen.

This is a one off script that determines all of the next hop gateway addresses based on the routing table (via ip route) and attempts to ping them.  If it fails to get a response it will check the ARP table to see if there is an ARP entry.  It will give the process about 20 seconds per and then kill the attempt so the process doesn't take forever.  

We use this script to capture results nightly as well so we know how it is supposed to look on a regular basis.

#!/bin/bash
#
# [Ivan Moore]
#
# Determine all next hop gateways from routing table and ping
# to make sure we can reach them.  If no ping response is received
# check ARP table to see if we have L2 just in case the device is
# not allowed to respond.
#
# 11/19/2015

VERSION=1.0.1

# Program name: ping script to ping next-hop addresses
date
ip route | awk '/via/ { print $3 }' | sort -u | while read output
do
    ping -c 1 -w 1 "$output" > /dev/null
    if [ $? -eq 0 ]; then
      echo "node $output is up"
    else
      echo " "
      echo "node $output is down"
      echo "Checking for an ARP entry in case PING is disabled:"
      arp -a $output &
      TASK_PID=$!
      sleep 20
      kill $TASK_PID >/dev/null 2>&1
      echo " "
    fi
done
0 Replies

Leaderboard

Epsum factorial non deposit quid pro quo hic escorol.

Upcoming Events

    CheckMates Events