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.
Hey Linux Community,
I have a question, my first, a likely not my last. We are monitoring several Linux servers, my main concern is for two servers in particular, they are on *.*.*.49, and *.*.*.50 with three of the same instances on each, we have been arguing with our developers as their bugs, alongside Users over-searching keep causing the instances to crash. This is a simple process of logging in SSH (eg. putty), entering a username/password running an "su -" command, and again entering the root password for the respective host, then running a "grep java" command to get the process list up, finding the PSID for the offline instance and killing it, waiting for it to restart.
Now, even though this does take a little time, it is an easy process, however we have some people working on the helpdesk who are wanting to do server monitoring over weekends to earn some extra cash, and they are all but computer illiterate. I was hoping to make the process as simple as possible for them so they could see which instance was failing and simply run a script which would remotely kill the process. We already have monitoring in place, so it's just the script that is the issue.
I was wondering if any genius knows of any script that would be able to pull the PSID from the instance name, and kill said instance, without the need of using putty (or alternate)?
I'm not entirely sure this is possible, but I would be eternally grateful if anyone has any ideas that could aid me.
Hi Tobi, thanks for your swift reply, however, I am already aware you can pull up the PID, my main concern is how I can simply run a kill command, ideally on a process name (as PID can change), so I can simply execute a script remotely, ie, via a html interface.
For example, one of the instances running is call mnet0104, when viewing each of the instances, we can tell when this process has crashed, all I want to do is as simply as possible, run a remote execution of a script, that will execute a kill command on that process. I would obviously need some way of logging into the server (possibly using something similar to that of a sendkey command in vbscript). Ideally this could all be done by executing one file remotely (and possibly have it prompting for a login)
If you want to run kill on a name instead of a PID you should have a look at the killall command. Also, if you want to start your script from a web-interface you should have a look at this thread.
If you want to do it with SSH, you can start a script on your server with the ssh command like this:
ok, I have looked into it all, I can create a web interface with php, which is no problem, however it will be a problem if I can't automate the kill process without having to discover the PID each time.
Even though it would appear the killall command is a good idea (as the instance name wouldnt change), for some unknown reason it doesn't work.
there are several processes, each of them a different instance, the following is just one of the ones I've pulled out of the many.
after entering:
ps -ef | grep java
The problem is that the killall command kills processes by program name, and your program name is not MNet0102. The program name is java. Using killall in this situation would result in all three of your WAS instances being killed.
This is where pgrep is your friend. It's the functional equivalent to ps -ef | grep <string>, only all it returns is the PID of the matching process. This should find what you're looking for:
Code:
pgrep -f MNet0102
And once you've verified pgrep works, you can use its cousin pkill to actually perform the kill.
Can I ask why you want to use kill and not the stopServer.sh command?
Last edited by SL00b; 05-06-2011 at 08:35 AM.
Reason: Fixed command strings.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.