![](/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.