#!/bin/bash

if [ "$1" == "--help" ] || [ "$1" == "" ]; then
 echo -e "\nsiptop.sh [PBX_bin]\n"
exit
fi

PBX_PID=`ps -e | grep $1 | awk '{ print $1; }'`
if [ "$PBX_PID" == "" ] ; then
 echo -e "\nsiptop.sh [PBX_bin]\n"            
exit
fi
rm siptop.log
echo "Start logging CPU usage of $1"
echo "After finished tests pres Ctrl+c"
top -d 1 -b -p $PBX_PID > siptop.log

if [ "`tail -2 siptop.log | head -1 | awk '{ print $(NF) }'`" == "$1" ]; then 
	exit
else
	echo -e "\e[00;31mSomething is wrong PBX is not working or changed PID!!!\e[00m"
fi
