Script for killing several processes and then launching them again
Hello,
We use a Java application that crashes occasionally. When it does, I have an external application that notices it and sends me an email, at which point, I need to kill the processes and then launch tomcat again. I found on another forum this command: Code:
kill -9 `ps -aef | grep 'tomcat' | grep -v grep | awk '{print $2}'` I think it's suitable if the result of the ps is a single line, but in my case, I get 3 lines, so I don't know how to make it run all on 3 processes. Also, I need to run afterwords the following command: Code:
/etc/init.d/tomcat6 start Thanks, David |
Quote:
If by "help", you mean "can someone write the script for me?", then no... As with all requests like this, post what you've written so far, and where you're getting stuck, and we'll be happy to help you. Otherwise, you can find many good bash scripting tutorials on Google, to help get you started. HINT: look at the "killall" command, and/or the "while" directive in bash scripting, to kill multiple PID's. |
Quote:
Thanks. |
In addition to what suggested by TB0ne, you can take a look at pkill. The line of code you found is totally superfluous, since you can force ps to print the needed information using the correct options (no need to grep, extract and so on). Moreover pkill joins the functionality of ps and kill together. A simple command can do the job. See man pkill for details.
|
Quote:
|
pkill result needs to be checked
Hello,
I noticed that pkill doesn't always kill all the processes. I think that I should include in the script a verification of pgrep's result and if there's still a process active, run pkill again. What is the correct syntax for the following condition? Code:
while [ **pgrep java** != "" ]; do |
All times are GMT -5. The time now is 03:07 PM. |