Script for killing several processes and then launching them again
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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 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
Can anyone help me with the script?
If by "help", you mean "assist you because you've got a problem", then sure.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.