I can't directly access target host, need ssh as a proxy.
How can I kill a process from local use ssh ? I try this:
ssh root@$center "ssh root@$ip \"ps -ef|grep -v grep|grep $target_dir/$main|awk '{print \$2}'|xargs kill\""
it got error:
kill: can't find process "root"
And how to avoid error where process not exist ?
Description. The kill command sends a signal (by default, the SIGTERM signal) to a running process. This default action normally stops processes. If you want to stop a process, specify the process ID (PID) in the ProcessID variable.
Suppose your process' name is name
, then you can try something like this:
ssh hostname "pid=\$(ps aux | grep 'name' | awk '{print \$2}' | head -1); echo \$pid |xargs kill"
Use pkill -f
to easily kill a process by matching its command-line.
ssh root@$center ssh root@$ip pkill -f "$target_dir/$main"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With