#!/bin/sh

if [ x$1 = x ]; then
echo "Usage: jsmon {PSDomain}"
exit 1
fi

TUXCONFIG=$PS_HOME/appserv/$1/PSTUXCFG
PS_SERVER_CFG=$PS_HOME/appserv/$1/psappsrv.cfg
myPID=$$
i=1

export TUXCONFIG PS_SERVER_CFG myPID
while [ 'a' = 'a' ]
     do
     #clear
     tmadmin 2> /dev/null > /tmp/psstat1.$myPID <<EOF
psr
quit
EOF

     tmadmin 2> /dev/null > /tmp/psstat2.$myPID <<EOF
pclt
quit
EOF

     tmadmin 2> /dev/null > /tmp/psstat3.$myPID <<EOF
pq
quit
EOF

     USER=`grep "IDLE/W" /tmp/psstat2.$myPID | wc -l`
     BUSY=`grep "BUSY/W" /tmp/psstat2.$myPID | wc -l`
     USER=`expr $USER + $BUSY`

     QUEUES=`grep Q /tmp/psstat3.$myPID | grep -v Queue |awk '{print $2}'`

     if [ $i -eq 1 ]; then
     echo "Date   Time    " "`echo Clients $QUEUES | awk '{for (i = 1; i <= NF ; i++) printf "%s\t", substr($i,1,7)}'`"
     fi

     if [ $i -eq $LINES ]; then
     i=1
     else
     i=`expr $i + 1`
     fi

     echo `date '+%y%m%d %H:%M:%S'` $BUSY/$USER,"\t\c"

     for q in $QUEUES
     do
       echo "`grep $q /tmp/psstat1.$myPID | grep -v IDLE | wc -l | awk '{print $1}'`/`grep $q /tmp/psstat3.$myPID | awk '{print $3"/"$5}'`,\t\c"
     done
     echo

     sleep 1
done
