How to stop the process in shell scripting?

Hi all,

I have tried the below code to execute.

#! /bin/bash
date1=`date -d "today 08:00:00" +%s`
date2=`date -d "today 08:01:00" +%s`
path=/home/user01/red/IDC/sample
cd $path
java Cspsamp 111.19.5.172 7025 rd1 rd1  "5022=Query|5026=109378|4=627|5=E:VD|5042=$date1|5049=$date2"
valLaunch=`echo $?`
echo "Value after launch "$valLaunch
 
pid=`/bin/ps -fu user01 | /bin/grep "5022=Query|5026=109378|4=627|5=E:VD|" | /bin/grep -v grep| /bin/awk -F' ' '{print $2}'`;
kill $pid;

In above the below code is running continuously. I want to stop this process after 2 mins .

java Cspsamp 111.19.5.172 7025 rd1 rd1  "5022=Query|5026=109378|4=627|5=E:VD|5042=$date1|5049=$date2"

Function 0f above code-it giving me the o/p of perticular time range but the process doesn't stop

My aim is to display the final line i.e
echo "Value after launch "$valLaunch"

How is it possible??

Thanks

You can try something like this:

End=$((SECONDS+60))
while [[ $SECONDS -lt $End ]]
do
  : do something
done

hi kristinu

the code u have provided is not working,

u can consider the command like

 
ping 123.34.32.123
 

which gives the continious output. and i want to stop this process in between that and want to process the next command

If you copy/paste this peace of script after your command call within
your script you can set a timer (here the time is set to 30 secs)

#!/bin/tcsh
@ counter = 0
while ($counter <= 30)
   sleep 1
   @ counter++
end

@kristinu
The problem appears to be that the Java program does not exit after completing the query. Therefore no subsequent commands in the script do not execute.
I'm not quite sure where a csh script would help.

Can he background it?