如何正确地写里面的命令(SSH)命令? [英] how to correctly write command inside commands (ssh)?

查看:102
本文介绍了如何正确地写里面的命令(SSH)命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是我有工作

这只是与前pression它返回一个数字一杀

It's just a kill with an expression which returns a number

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"'

这是不行的,我的猜测是,它被夹杂了'。

It doesn't work, my guess is that it gets mixed up with the ''.

试过选项

摆脱大多数中的kill命令:

Escaping most of the ' in the kill commands :

 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"'

千万不能工作,我做了很多尝试其他的,但不能使它工作。

Do not work either, I did many other tries but can't make it work.

任何想法?

添加笔记

我的系统不支持pkill的命令

My system doesn't support pkill command

推荐答案

删除该的bash -c 符号。假设你不重写命令中使用 pkill的,那么你就需要这样的:

Drop the bash -c notation. Assuming you don't rewrite the command to use pkill, then you need something like:

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'

请注意,我用的命令里面的双引号执行。幸运的是,没有任何的命令,其中会的问题是否使用单引号或双引号。

Note that I used double quotes inside the command to be executed. Fortunately, there was nothing in the command where it would matter whether single quotes or double quotes were used.

与嵌入式单引号'版本不工作,因为你不能在一个单引号字符串中嵌入单引号。你可以,如果你必须写'...'\\''...'在两个省略号之间得到一个单引号。第一个 终止当前的单引号字符(即使preceding字符是一个反斜杠;还有一个单引号字符不逃逸);在 \\ 生成一个单引号;第三 中心组再次恢复了单引号字符。

The version with 'embedded single quotes' doesn't work because you can't embed single quotes in a single-quoted string. You can, if you must, write '…'\''…' to get a single quote in between two ellipsis. The first ' terminates the current single quoted string (even if the preceding character is a backslash; there are no escapes in a single quoted string); the \' generates a single quote; the third ' in the centre group resumes the single quoted string again.

因此​​,在你尝试:

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"'

bash命令看到:

the Bash command sees:

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"

这意味着的grep 变,你想要的人多参数等它彻底打破了意义。

which means grep gets multiple arguments where you wanted one, etc. It completely breaks up the meaning.

嵌套引用惯例是很难 - 真的很难

Nesting quoting conventions is hard — really hard.

这篇关于如何正确地写里面的命令(SSH)命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆