WebSphere Issues

18/04/2017

Script to check connectivity between single or multiple hosts – telnet

Filed under: Other — Ishtiaque @ 11:07 am

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

Create a free website or blog at WordPress.com.

%d bloggers like this: