How to stop the process in shell scripting?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to stop the process in shell scripting?
# 1  
Old 03-20-2012
How to stop the process in shell scripting?

Hi all,


I have tried the below code to execute.

Code:
#! /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 .

Code:
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
# 2  
Old 03-20-2012
You can try something like this:

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

# 3  
Old 03-21-2012
hi kristinu


the code u have provided is not working,

u can consider the command like

Code:
 
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
# 4  
Old 03-21-2012
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)

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

# 5  
Old 03-21-2012
@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.

Last edited by methyl; 03-22-2012 at 04:21 PM..
# 6  
Old 03-21-2012
Can he background it?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to display only the first 5 running process using top in shell scripting?

topfunc() { top } topfunc Here i used the top command inside a function,and i called the function. when executing this bash file i get all the process which are using by the kernel i just want to display only the first 5 running process. is it possible? (7 Replies)
Discussion started by: Meeran Rizvi
7 Replies

2. Shell Programming and Scripting

Shell scripting errors for ftp process

Hi i am facing problem in shell scripting for ftp process getting following errors here is the script & result vi GtpTxnlogs_ftp.sh "GtpTxnlogs_ftp.sh" 40 lines, 921 characters #!/usr/bin/bash ###################################################################################### #... (4 Replies)
Discussion started by: Sarmistha
4 Replies

3. UNIX for Dummies Questions & Answers

Shell Scripting Stop/Start Application

I did a search of these forums but couldnt find a suitable resolution. I am attempting to script a stop and start of an application on AIX. Such as: However it has authentication where username and password prompts will appear after running the above command requiring input from a... (2 Replies)
Discussion started by: Soupy
2 Replies

4. Shell Programming and Scripting

How to process multiple input files using Shell scripting

Hi, I would like to write a for loop that does the following: I have a file called X.txt and other files called 1.txt,2.txt, .....,1000.txt. I want to substitute the 6th column of the file X.txt with 1.txt and store the output as X.1. Then I want to do the same with X.txt and 2.txt and store... (0 Replies)
Discussion started by: evelibertine
0 Replies

5. Shell Programming and Scripting

How to stop monitoring of servers at the time of reboot through shell scripting?

We have number of servers which belongs to platforms Solaris, AIX,HP-UX and LINUX. Monitoring tool 'Patrol Agent' process run on the servers to check for the server health and communicate with the Patrol server through the port 5181. During scheduled reboot and maintenance of servers we do receive... (1 Reply)
Discussion started by: subharai
1 Replies

6. Shell Programming and Scripting

Shell Scripting not showing in process when it goes to sleep

Hi All, Here is my script: sleep_time=`echo "9.6 * $num_servers"|bc| cut -d. -f1` if ; then sleep_time=3600;fi ### Allow the compare script to kick in after 1 hour at the least logger "Sleeping for $sleep_time seconds ...Will call compare.sh thereon" $act_log sleep $sleep_time #sleep... (3 Replies)
Discussion started by: ntgobinath
3 Replies

7. UNIX for Dummies Questions & Answers

Wait Process in Shell Scripting.

Hello, I have a script that needs to wait till the previous process is done within the same script.But my script doesnt wait till that it is done.Can anyone suggest how I can stop my process till the previous task is done. I tried 'wait' but I dont have a static process id so is there... (2 Replies)
Discussion started by: sud
2 Replies

8. Shell Programming and Scripting

Background Process Shell Scripting

I have a following program: echofunc() { filename=$1 echo "reading $filename" while read line do echo $line; sleep 6; done < $filename } split -5 new.dat ls x* > input.dat while read file do echofun $file & done < input.dat (3 Replies)
Discussion started by: dhieraj
3 Replies

9. Shell Programming and Scripting

Shell stop process after found value in file

hi guys can somebody help me here... i've a file that contains total of ip that connects to my server and their ip like this : 80 80 xxx.xxx.xx.xxx 75 75 xxx.xxx.xx.xxx 73 73 xxx.xxx.xx.xxx where first columns and second were the total connections... ... (0 Replies)
Discussion started by: kriezo
0 Replies
Login or Register to Ask a Question