ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I want to manage some servers using ssh, so I wrote a couple of scripts. One of the scripts starts a screen under root and within the screen new processes will be started using one of the user acounts. Except starting, I also want to kill processes using ssh. On the local machine the command is:
As you can see I have multiple processes used by two different kinds of users. Below (and up) are the right commando's for killing the processes. I failed using any of the commands using ssh. I tried to add some quotes or ( ) but without any succes. I also tried pkill, but without any luck.. the screen proces keeps running! This is no good because I also have some scripts listing the screen status. Anyone here can tell me how to solve this problem?
Interesting...i thought that would work. Never really killed a remote process before. Anyhow, I came up with a different solution (and I verified that it works). Just make a shell script on server01 to kill the process. Then ssh into server01 and execute that shell script.
on the local machine, and then call ssh with a bunch of local process ids, which will not work.
The notation with $() is the same as putting things between backquotes ``.
The trick is to postpone execution of the backquotes stuff untill logged in at the remote end. To do this, you have three possible alternatives:[list=1][*]Put a backslash before the backquotes. Then the shell on the local machine will remove the backslash, and the remote end will do the actual execution[*]Put a backslash before the dollar sign. Same argument as above.[*]Put the entire thing within single quotes. Doesn't apply here, because the argument to awk is already between single quotes, and you can't nest them. Note that the argument to awk is between single quotes for exactly the same reason. If it weren't then the shell would try to evaluate the $2, and awk would never see it. If you were using cut instead of awk, then putting everything in single quotes would be a viable option.[/list=1]
eval is also a technique to postpone execution of a command, but I guess in this case it is redundant (though it doesn't hurt either).
Note that all of this is my interpretation of the bash manpage, I didn't actually test it.
It builds a command line that is to be executed on the remote host, while the previously posted scripts were executing the pid search on the local host.
If you want to understand the details, execute it first after replacing kill by echo, and second after removing the eval command.
nixcraft, you're right pkill is a far simpler answer to the question.
Just one comment, I wouldn't use "-9" which is bad behaviour.
-9 is only to be used on processes that won't die after being sent "regular" signals that allows them to shutdown properly.