Killing process!!!!

Hi friends,

i m in big trouble....

i have one script which connects two server ...like below..

script1.sh
-------------------------------------
bash test.sh &
eval x=$@
export x=`echo $x`
#echo $x
#
ssh user@8.2.5.6 bash /mbbv/location/script.sh $x|sed '/Binary file/d'
----------------------------------------------

here first one which is "bash test.sh &"
i want this to be run in backend...purpose is to check whether the entire script is taking much time or not...if its taking more than 1 min then test.sh will kill the current process and will return message "saying that process is delayed"

i have given code for test.sh also..
---------------------------------------------------
pid=`ps -ef |grep "script.sh"|awk '{print $2}'|tail -2|head -1`
sleep 60
ps -ef |awk '{print $2}'|grep $pid >/dev/null
if [ $? -eq 0 ]
then
kill -9 $pid > /dev/null
echo "Server seems to be busy. Please try after some time. Sorry for the inconvenience"
fi
exit 1;
---------------------------------------------------------
my problem:

i have one jsp tool which will trigger the first script and will display whatever comes from unix script(script1.sh)...but when i run this script with this condition(60 sec process time) ...its not considering the test.sh script..instead its running and doing all the process with more than 1 mint..

but if i checked the same thing without jsp tool ...if i run manually like below..

bash script.sh 444444444
then its returning the correct message ..

can anyone help me on this please.....

Thanks
sha

This limit program might help you a bit. It runs the specified command but kills it after a specified number of seconds. Might solve your entire problem.