Scripting‎ > ‎Linux shell‎ > ‎

A nodes ping test script

Thank you for visiting this page, this page has been update in another link A nodes cross ping test script
Here is a quick script, quite easy, but useful if you have large number of nodes to manage and you want to make sure their network can reach each other. It's true, there are tons of tools you can use to monitor a node, but when you suspect network problem, you want to make sure network connection between nodes. Here it is.
It uses quiet ping mode, so doesn't generate too much noise on your screen.


#!/bin/bash

if [ -f "/etc/release" ] ; then
  myname=$(hostname)
  cmd="/usr/sbin/ping -v -U"
else
  myname=$(hostname -s)
  cmd="ping -q -c 1 -w 2"
fi
me=$(whoami)

mylog="/var/tmp/"$myname"_"$me"_ping.log"

hostlist="aaa bbb ccc ddd "


issues="no"
for h in $hostlist ; do
  out=$($cmd $h 2>/dev/null)
  if [ $? -ne 0 ] ; then
    issues="yes"
    ts=$(date +"%b %d %H:%M:%S")
    lastline=$(echo "$out"|tail -1)
    echo "$ts $h $lastline" >>$mylog
  fi
done

if [ "$issues" = "yes" ] ; then
  echo -e "\e[0;31m Some ping lost seen for $myname, see $mylog for detail ! \e[0m"
else
  echo -e "\e[0;32m All good, $myname can ping all other nodes !\e[0m";
fi



Comments