1 #!/bin/sh 2 3 4 #-------------------------------------------------------------------------# 5 # port.monitor # 6 # This script verifies that "something" is listening on the port named # 7 # If this doesnt work for your OS, please submit a patch # 8 # # 9 # Usage: port.monitor portnum [specific IP addr] # 10 # # 11 # The default is to look for a 'globally bound port' # 12 # If your process binds to a specific IP address. you MUST specify that # 13 # IP address, or this script will not detect it # 14 # # 15 # Standard UNIX status: returns 0 on good, non-0 on bad. # 16 # # 17 # # 18 #-------------------------------------------------------------------------# 19 20 21 PATH=$PATH:/usr/sbin:/sbin:/etc 22 23 if [ "$1" = "" ] ; then 24 echo "port.monitor: ERROR: no port number given" 25 exit 1 26 fi 27 if [ "$2" = "" ] ; then 28 IPADDR='*' 29 else 30 IPADDR="$2" 31 fi 32 33 netstat -an | fgrep $IPADDR".$1"|grep LISTEN >/dev/null 34 35 if [ $? -eq 0 ] ; then 36 exit 0 37 fi 38 39 exit 1 40