在ssh之后执行一个命令

以下命令按预期工作:

ssh [email protected] "ssh [email protected] "mysqlshow"" 

但是以下不是:

 ssh [email protected] "ssh [email protected] "mysql test -Bse"show variables""" 

下面的部分在命令提示符下工作,但是当我执行ssh之前,如上所示执行失败。

 mysql test -Bse"show variables" 

你不能像这样嵌套双引号。 你要么逃避它们,要么改变你的方法。

尝试这个:

 ssh [email protected] "ssh [email protected] \"mysql test -Bse'show variables'\"" 

在命令ssh [email protected] "ssh [email protected] "mysql test -Bse"show variables"""你有多个双引号。 尝试逃避他们

 ssh [email protected] "ssh [email protected] \"mysql test -Bse\\\"show variables\\\"\"" 

或者,你可以放

 mysql test -Bse"show variables" 

转换成服务器上的脚本,然后通过SSH调用该脚本,如第一个示例中所示。 如果你这样做,确保可执行位设置正确,允许用户浸泡运行它。