Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Don't use rsh! It's not secure at all. Use ssh instead – Daenyth Jun 26 '10 at 0:59
up vote 5 down vote accepted

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.

rsh "remotemachine" pkill whatevertheprocessnameis

share|improve this answer
This answer is the bomb! I'm running zsh and tmux plugin. It prevented me from restarting my virtual machine the 4th time after switching to a new user and switching back again which causes a tmux to be run in a tmux. – Mark Oct 12 '13 at 4:21

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.

share|improve this answer

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

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.