if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ]
then
  echo "Usage: ips <Integrator user> <number of polls> <interval between two polls>"
  exit -1
fi

iuser=$1
maxPolls=$2
interval=$3

if [ ! -z "${maxPolls//[0-9]/}" ] || [ ! -z "${interval//[0-9]/}" ]; then
  echo "Usage: ips <Integrator user> <number of polls> <interval between two polls>"
  echo "             <number of polls> & <interval between two polls> must be integrers"
  exit -1
fi
 
#interval=`expr "$interval" \* 3600` # interval in hours
sleep $interval
outfile="`date +%m_%d_%Y_%H_%M`_integrator.ps"
date1="`date +%m/%d/%Y_%H:%M`"

NBTRK=0
NB=1
stop=0
 
echo $date1 "ips"
echo $date1>>$outfile
echo "Time PCPU VSZ PID COMM">>$outfile

while [ "$stop" -le 1 ]
do
date2="`date +%H:%M:%S`*"
echo $date2

pid1=`ps -u $iuser -o time,pcpu,vsz,pid,comm |grep r4edi`
pid2=`ps -u $iuser -o time,pcpu,vsz,pid,comm |grep procengi`
pid3=`ps -u $iuser -o time,pcpu,vsz,pid,comm |grep queue`
pid4=`ps -u $iuser -o time,pcpu,vsz,pid,comm |grep filerd`
pid5=`ps -u $iuser -o time,pcpu,vsz,pid,comm |grep table`
pid6=`ps -u $iuser -o time,pcpu,vsz,pid,comm |grep trace`
pid7=`ps -u $iuser -o time,pcpu,vsz,pid,comm |grep cfgserve`
pid8=`ps -u $iuser -o time,pcpu,vsz,pid,comm |grep trace`
pid9=`ps -u $iuser -o time,pcpu,vsz,pid,comm |grep survive`
pid10=`ps -u $iuser -o time,pcpu,vsz,pid,comm |grep logger`
pid11=`ps -u $iuser -o time,pcpu,vsz,pid,comm |grep timer`
echo $date2>>$outfile
echo $pid1>>$outfile
echo $pid2>>$outfile
echo $pid3>>$outfile
echo $pid4>>$outfile
echo $pid5>>$outfile
echo $pid6>>$outfile
echo $pid7>>$outfile
echo $pid8>>$outfile
echo $pid9>>$outfile
echo $pid10>>$outfile
echo $pid11>>$outfile

NBTRK=`expr "$NBTRK" + 1`

sleep $interval 

if [ "$NBTRK" = "$maxPolls" ]
then
stop=`expr "$stop" + 2`
echo "End Of Polling"
fi
done
