#! /bin/sh
# Shell script to get statistics on an Altura Linux Comm module.
# If the specified process is running, extract it's PID, then send it the
# SIGUSR2 signal, which will cause it to output its current statistics
# information.  Once the file is created, display it.
#
# "$Id: stats,v 1.1.1.1 2003/12/02 15:53:30 sbobcvs Exp $"
#
# ########################################################################
# For debug purposes
# set -x

# Check usage
if [ ${#} -lt "1" ]
then
	echo "Usage: $0 <process-name>"
	exit 0
fi

# See if the process is running ...
#pid=$(echo $(ps -a | grep ${1} | grep -v "grep" | grep -v "${0}"))
pid=`pidof ${1}`
if [ -z $pid ]
then
	echo "Process <${1}> not running."
	exit 0
fi

# Save any existing file off to an old one
rm -f /tmp/linux-comm-stats-old
mv /tmp/linux-comm-stats /tmp/linux-comm-stats-old

# Extract the PID from the "ps -a" output
# Don't need to strip off leading spaces - echo took care of that above
# and the following line does not strip off ALL leading spaces anyway.
# pid=${pid# *}

# Use pidof above instead of this next line - Works much better.
# pid=${pid%% *}

# Send this process the SIGUSR2 signal
kill -12 ${pid}

# Wait for the statistics file to be generated ...
while true
do
	if [ -f /tmp/linux-comm-stats ]
	then
		# Display the results and quit
		cat /tmp/linux-comm-stats
		echo "${1}:pid = ${pid}"
		exit 0
	fi
done

#
# End of "$Id: stats,v 1.1.1.1 2003/12/02 15:53:30 sbobcvs Exp $"
#

