1

我需要杀死特定模式的远程进程,推送启动路径并执行脚本。到目前为止,我尝试过

pid=$(ssh -q username@virt ps -ef|grep $APP|grep $PORT|awk '{print $2}')

ssh -q username@virt kill -9 $pid
ssh -q username@virt "find /shared/local/path1/app -name "start_app*" -exec grep -nl "9122" {} \;| xargs -0 -I '{}' bash -c 'pushd $(dirname {});bash {};'"

当我执行上述命令时,kill 处理工作正常。通过将文件夹推送到路径来查找脚本文件并执行脚本的最后一步不起作用。

由于某种原因,pushd 无法正常工作。本地服务器上的命令确实可以使用

find /shared/local/path1/app -name "start_app*" -exec grep -nl "9122" {} \;| xarg -0 -I '{}' bash -c 'pushd $(dirname {});bash {};'

请帮助更有效的解决方案来完成此任务。

4

1 回答 1

0

您在此处的引号中有错误:

ssh -q username@virt "find /shared/local/path1/app -name "start_app*" -exec grep -nl "9122" {} \;| xargs -0 -I '{}' bash -c 'pushd $(dirname {});bash {};'"

试试这个:

ssh -q username@virt "find /shared/local/path1/app -name 'start_app*' -exec grep -nl '9122' {} \;| xargs -0 -I '{}' bash -c 'pushd \$(dirname {});bash {};'"
于 2013-03-31T13:21:12.510 回答