Start/Stop process when a file is modified.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Start/Stop process when a file is modified.
# 1  
Old 01-14-2010
Start/Stop process when a file is modified.

I have a file which is modified via a web application & this may happen during any time of the day/week. This file is being used a config/list file for another shell script which runs 24hrs with a sleep of 200 secs.

I have writted a small script to kill the shell script when this config file is modified.

Let me know if there are any modifications to be made.

Code:
 
#!/bin/sh
x='find . -mmin +15 | grep configfile| wc -l'
PID='ps -ef | grep process.sh | grep -v grep | awk '{print $2}''
 
while :; do
     if [ x -eq 1 ]
   then
          kill -9 $PID
   sleep 30
          break
     fi
done
./process.sh
exit 0

# 2  
Old 01-14-2010
Code:
kill -9 $PID

You get a Useless Use of kill -9 award! Smilie To wit:

Quote:
No no no. Don't use kill -9.

It doesn't give the process a chance to cleanly:

1) shut down socket connections

2) clean up temp files

3) inform its children that it is going away

4) reset its terminal characteristics

and so on and so on and so on.

Generally, send 15, and wait a second or two, and if that doesn't
work, send 2, and if that doesn't work, send 1. If that doesn't,
REMOVE THE BINARY because the program is badly behaved!

Don't use kill -9. Don't bring out the combine harvester just to tidy
up the flower pot.
If you're on linux, the killall command may be useful to kill a process by executable name instead of grepping awkward stuff to find it. On other systems though, killall has a completely different and absolutely literal functionality. Smilie
# 3  
Old 01-14-2010
The process which is killed is a shell script which runs to collect config statistics.
You mean to say that I can use killall PID instead of kill -9 PID.
# 4  
Old 01-14-2010
Quote:
Originally Posted by Lancel0t
The process which is killed is a shell script which runs to collect config statistics.
You mean to say that I can use killall PID instead of kill -9 PID.
I told you two separate things.

1) Don't use kill -9. Use other signals than 9 unless absolutely necessary for all the reasons listed above.

2) the killall command on linux(but ONLY on linux) will let you kill a process by name without having to grep for it.
# 5  
Old 01-14-2010
Couldn't you modify your "process.sh" to check if the config file has been modified.
That because it sleeps 200 secs and ther is no need to check every 30 secs.
Or have i misunderstood ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Stop and start a process every X hours

Hi, I have a parallelized Mathematica program that spans across 8 MathKernels processes running at 100% and one MathKernel (highlighted in blue) running at < 10% that controls the other 8. They look like this on the cluster: https://www.unix.com/attachment.php?attachmentid=5111&stc=1&d=1381245618... (2 Replies)
Discussion started by: giovform
2 Replies

2. Shell Programming and Scripting

search last modified file and process it

Hello, trying to build a shell script that - searches in defined location for similar files (eg. containing pattern in file name) - Identifies last modified - stores name in variable for processing Thanks a lot (4 Replies)
Discussion started by: alice07
4 Replies

3. UNIX for Dummies Questions & Answers

Stop/Start vs. Restart

Is there any functional difference between: issuing separate stop/start commands like this; super (handler) (instance) stop super (handler) (instance) start versus issuing a single recycle command like this; super (handler) (instance) restart (3 Replies)
Discussion started by: Newbix
3 Replies

4. Shell Programming and Scripting

Servers Start and Stop

HI I am using below code to start and stop servers but it is not working ,how to run the script please suggest me ,if any errors in the script please let me know. #!/bin/bash IMS_START="/Webserver/AppServer/bin/startServer.sh" IMS_STOP="/Webserver/AppServer/bin/stopServer.sh" case "$1" in ... (1 Reply)
Discussion started by: RG18173
1 Replies

5. Shell Programming and Scripting

Servers Stop and Start

Hi, Every time i want to stop and start servers using PuTTY,i have to execute 6 to 10 commands every time ,i need shell script(program) for execute those commands in single command.Is it possible plz suggest me. (3 Replies)
Discussion started by: RG18173
3 Replies

6. Shell Programming and Scripting

Start Stop Restart

I'm wondering how I should make a script that can start, stop, and restart another script. What I need to be able to do, is start and stop a perl script from the command line. The easiest way of doing this seems to be to have another script, starting and stopping the other script. I have BASH,... (7 Replies)
Discussion started by: Bakes
7 Replies

7. HP-UX

ypbind start/stop

Hi, How to start or stop ypbind on HP-UX machine. Searched a little but could not find. thanks, (2 Replies)
Discussion started by: jredx
2 Replies

8. 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

9. Solaris

stop a process to start at system startup

Hi all! I'm running Solaris 10 and have a question about how i can stop a certain program to start at system startup,for example, as it is now sendmail is starting but i don't need sendmail,on the other hand so would i be very glad to get cups up and running at startup, anyone who can explain where... (3 Replies)
Discussion started by: larsgk
3 Replies

10. AIX

Start Stop Apache

I am in the process of reorging my Lawson db. I need to turn off the RMI server...not a problem. However my instructions also state that I must also shutdown my Servlet Container....I believe it is Apache. I have looked in /usr/apache/bin/apachectl What is the command for stopping and... (2 Replies)
Discussion started by: MILLERJ62
2 Replies
Login or Register to Ask a Question