Checking the port status of a remote host

Hi there

I am in the process of writing a script to check whether a port on a remote system is up or not.

Here's what I have so far:

#!/bin/bash

        telnet xx.xx.xx.xx 80 | (echo "^]")

if [[ `echo $?` != 0 ]]; then

        echo "Please check Web services " | mailx -s "Please check webservices for frontend" email@work.com
       
fi

Would this work? I'm not sure if the exit status code would be a reflection of the telnet or the break sequence, if that makes sense?

Your input would be greatly appreciated.

should work:

#!/usr/bin/ksh
if echo "GET; exit" | mconnect -p 80 xx.xx.xx.xx > /dev/null 2>&1 
 then 
  exit 0
 else
  echo "Please check Web services " | mailx -s "Please check webservices for frontend" email@work.com
  exit 1
fi

regards

  • pressy
1 Like