【发布时间】:2015-06-17 22:32:45
【问题描述】:
这是我的有效命令
这只是一个返回数字的表达式的杀戮
kill $(ps -ef | grep '[m]atchbox-panel --titlebar --start-applets showdesktop,windowselector' | cut -f8 -d' ') &> /dev/null
这里是我平时使用的ssh
bash -c 'timeout 120s ssh -o StrictHostKeyChecking=no root@192.168.155.XXX "cd NightTest"'
我尝试将两者结合起来
bash -c 'timeout 120s ssh -o StrictHostKeyChecking=no root@192.168.155.148 "kill $(ps -ef | grep '[m]atchbox-panel --titlebar --start-applets showdesktop,windowselector' | cut -f8 -d' ') &> /dev/null"'
它不起作用,我猜它与''混淆了。
尝试过的选项
在 kill 命令中转义大部分 ' :
bash -c 'timeout 120s ssh -o StrictHostKeyChecking=no root@192.168.155.148 "kill $(ps -ef | grep \'[m]atchbox-panel --titlebar --start-applets showdesktop,windowselector\' | cut -f8 -d\' ') &> /dev/null"'
也不行,我做了很多其他的尝试,但无法成功。
有什么想法吗?
添加备注
我的系统不支持 pkill 命令
【问题讨论】:
-
为什么首先使用
bash -c '…'符号?为什么不只是timeout …?对bash -c '…'使用单引号会使处理变得非常复杂。您需要在要执行的命令周围加上一层单引号。 -
您将两者结合起来的代码对我有用。 “它不起作用”是什么意思?
-
@Arkanosis:组合版本在本地计算机上评估
$(ps …),而不是在ssh-连接到的主机上。 -
非常感谢!关于 -c 是因为我通常在一个字符串中发送许多命令( command1 && command 2 )
-
@JonathanLeffler:哦,没错!谢谢。