![](/img/trans.png)
[英]Exit code of previous command execution is always 0 — In Remote Shell Execution $?
[英]command execution on remote server shell
我在外壳上使用ssh在远程服务器上运行一个简单命令。
我目前登录myHost01
和我在运行此命令myHost02
预期的结果是this is a test myHost02
。 但是,我得到的this is a test myHost01
这是我的命令
sshpass -p root ssh -q root@127.0.0.2 "echo this is a test `hostname`"
我不知道为什么它要使用我从中运行命令的服务器的主机名!
还值得注意的是,当我运行此
sshpass -p root ssh -q root@127.0.0.2 "hostname"
我得到myHost02
(这是正确的输出)
用单引号将命令传递,如下所示。 双引号使外壳程序就地执行命令替换hostname
(本地),并将结果字符串this is a test myHost01
给ssh
this is a test myHost01
sshpass -p root ssh -q root@127.0.0.2 'echo this is a test `hostname`'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.