我无法直接访问目标主机,需要ssh作为代理.
如何从本地使用ssh杀死进程?我试试这个:
ssh root@$center "ssh root@$ip \"ps -ef|grep -v grep|grep $target_dir/$main|awk '{print \$2}'|xargs kill\""
它有错误:
kill: can't find process "root"
如何避免过程不存在的错误?
Jay*_*hoi 17
假设您的进程名称是name,那么您可以尝试这样的事情:
ssh hostname "pid=\$(ps aux | grep 'name' | awk '{print \$2}' | head -1); echo \$pid |xargs kill"
用于pkill -f通过匹配命令行轻松终止进程。
ssh root@$center ssh root@$ip pkill -f "$target_dir/$main"