[TriLUG] OT - Connectivity Test?

Owen Berry oberry at trilug.org
Mon May 7 12:47:24 EDT 2007


On Thu, May 03, 2007 at 10:20:38AM -0400, Howard Boyd wrote:
> I would like to create a script (preferably Korn Shell) that will test 
> connectivity between two Unix (AIX) servers. Ping isn't an option for me 
> as one of the servers is in a DMZ and PING requests aren't allowed through 
> the firewalls. The backend system is running an HTTP server. Can someone 
> provide a command that I can use to test connectivity between the two 
> servers? Thanks,
> 
> Howard

Apologies if anyone already received this, but I sent it out on Friday
afternoon and it seems to have disappeared into cyberspace.

It's a little late in coming, but below is a Korn shell script that can
be used to perform a "ping" on any port. It uses telnet and standard
shell utils. Gives a 1 line status message, and a return code of 0 on
success. Works for me on AIX 5.3. Comments are non-existant, so let me
know if you have questions.

Enjoy!
Owen

  #!/usr/bin/ksh
  
  HOST=$1
  PORT=${2:-80}
  
  if [ $# -eq 0 ]; then
      echo "Error: You must provide a host name."
      exit 1
  fi
  
  T_PID=0
  
  function checkResult
  {
      while read -p; do
          echo $REPLY | grep "^Connected" > /dev/null
          if [ $? == 0 ]; then
              echo "$REPLY"
              exit 0
          fi
      done
  
      echo "Could not connect to ${HOST}."
      exit 1
  }
  
  function stillWaiting
  {
      ps | grep "^ *${T_PID}" | grep -v grep | wc -l
  }
  
  (echo "quit" | telnet $HOST $PORT 2>&1) |&
  T_PID=$!
  
  sleep 1
  if [ `stillWaiting` -eq 0 ]; then checkResult; fi
  
  sleep 5
  if [ `stillWaiting` -eq 0 ]; then checkResult; fi
  
  kill $T_PID
  echo "Timed out waiting to connect to ${HOST}."
  exit 2




More information about the TriLUG mailing list