I would like to issue a kill command across many *nix machines. I'm attempting to do something like this:
rsh <remotemachine> ps -ef | grep <somepattern> | awk '{print $2}' | xargs n1 -t -i kill {}
But that issues the kill command on the local machine, not the remote machine. I've also tried something like this:
rsh <remotemachine> kill $(ps -ef | grep <somepattern> | awk '{print $2}')
But that's not working for me either.
Assuming you're working on machines that have it, you could also use a more specific utility, like pgrep or pkill. This means you don't have to use grep, awk, or xargs. This would simplify things quite a bit.
http://linux.about.com/library/cmd/blcmdl1_pkill.htm
rsh "remotemachine" pkill whatevertheprocessnameis
ssh user@someserver "ps -ef | grep | awk '{print $2}' | xargs n1 -t -i kill {}"
I refuse to use any other method of remote console other than SSH. It's also virtually everywhere.
On a random aside, I'd recommend you use SSH. RSH sends passwords in the clear, SSH is far more secure.
Either way, you're going to need to escape characters that the local shell is going to interpret. Namely, those pipes. And the single quotes. And the dollar sign. I think the curly braces are OK, but I'd probably be paranoid and do those two. Failure to do this results in the RSH command only getting passed up to the first pipe, then the output of that command getting piped locally to grep, awk, etc.
This is the kind of command that gets irritating. Try this:
rsh <remotemachine> ps -ef \| grep <somepattern> \| awk \'\{print \$2\}\' \| xargs n1 -t -i kill \{\}
--Christopher Karel
This is possible on Windows machine with taskkill, pskill or another command :) Regretably, it is not possible on Linux/UNIX machine without using ssh, rsh or another remote session tool.