Script to check connectivity between single or multiple hosts – telnet

Alternate to telnet commands to check single host:

  • echo > /dev/tcp/{host}/{port} && echo “SUCCESS” || echo “FAILED”
  • timeout 1 bash -c ‘(If output 0 then Sucess else Failed)

Script to check connectivity between multiple hosts:

#!/bin/bash
SRC_HOSTS=(‘src1’ ‘src2’ ‘src3’ ‘src3’ ‘src4’)

DEST_HOSTS=(‘dest1’ ‘dest2’)
PORT=1521
TIMEOUT=1

for src in ${SRC_HOSTS[@]}; do
echo “—Testing connection from $src—”

for dest in ${DEST_HOSTS[@]}; do
ssh root@$src “timeout $TIMEOUT bash -c ‘ /dev/null 2>&1

if [[ $? -eq 0 ]]; then
echo “SUCCESS: $dest”
else
echo “FAILED: $dest”
fi
done
done
exit 0

Note: You could use IP address instead of hostnames in SRC_HOST and DEST_HOST variables.

Advertisements

About Ishtiaque

I am IBM Certified Infrastructure Systems Architect, TOGAF 9 Certified, ITIL V3 Foundation certified and Oracle Certified Export in Java Web Component Developer with over 10 years of support and development experience in IBM middleware software and Java. Additionally, have a sound grip in databases, Linux and OpenStack administration. I hold the following certifications: IBM Certified Infrastructure Systems Architect TOGAF 9 Certified Oracle Certified Expert, Java EE6 Web Component Developer Oracle Certified Professional – Java 6 Programmer ITIL v3 Foundation Certified IBM Certified Solution Architect – Cloud Computing Infrastructure V1 IBM Certified System Administrator – WebSphere Portal V8, V7, V6.1, V6 IBM Certified System Administrator – WebSphere Application Server V7, V6.1 IBM Certified System Administrator – AIX V7 IBM Certified System Administrator – WebSphere MQ V7 IBM Certified Deployment Professional – Business Process Manager Advanced V7.5 IBM Certified Solution Advisor – Cloud Computing Architecture V3 IBM Certified Solution Developer – WebSphere Portal V5.1
This entry was posted in Linux and tagged . Bookmark the permalink.