I want to ssh on a remote machine and kill all java process on that machine. I have authorized this machine to ssh on without password so I use command:

ssh remote "kill -9 `pgrep java`"

but I got:

bash: line 0:kill (23779) -No such process

How can I fix it?



ssh remote "kill -9 `pgrep java`"

will run the subprocess pgrep java on your machine, not the remote one. If you want to run it on the remote machine, you need to enclose the arguments with apostrophes instead of double quotes:

ssh remote 'kill -9 `pgrep java`'
|improve this answer|||||

Just replace kill with pkill:

ssh remote "pkill java"
|improve this answer|||||
  • This is a workaround using different commands. The original problem is not resolved. See my answer. – Jakuje May 5 '17 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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