#! /bin/sh

# $Id: check_msg_servers.sh,v 1.3 1999/10/06 14:33:39 v2kea318 Exp $
# $Log: check_msg_servers.sh,v $
# Revision 1.3  1999/10/06  14:33:39  v2kea318
# *** empty log message ***
#
# Revision 1.2  1999/08/19  15:40:46  v2kea318
# Split the netstat check into two checks:  one to make sure there is a
# socket on the required port, and the other to make sure it is in
# LISTEN status.
#
# Revision 1.1  1999/08/19  15:37:17  v2kea318
# Initial revision
#
#***************************************************************************
#
# A simple script to check on the server sockets associated with the msg
# system.
#
#***************************************************************************

[ "$USER" = "" ] && USER=`whoami`

check_socket() {
    progname=$1
    port=$2

    # is the program running?
    pid=`ps -ef | grep ^$USER | grep "$progname"' *$' | awk '{ print $2 }'`
    if [ "$pid" = "" ] ; then
	echo "$progname isn't running!" 1>&2
	return
    fi
    echo "$progname is running with PID = $pid"

    # get the netstat line for this port.
    stat=`netstat -a | awk '$4 ~ /\.'$port'$/ { print }'`
    if [ "$stat" = "" ] ; then
	echo "Unable to find any socket running on port $port!" 1>&2
	return
    fi
	
    # check that the server socket is accepting connections.
    acc=`echo $stat | grep 'LISTEN *$'`
    if [ "$acc" = "" ] ; then
	echo "$progname is not accepting connections!" 1>&2
	return
    fi
    echo "$progname is accepting connections on port $port"
}

#***************************************************************************

check_socket msg_server 2351
check_socket msgd `awk -F: '$1 ~ /^'$USER'$/ { print $3 }' /etc/passwd`


