[英]command execution on remote server shell
I am running a simple command on remote server using ssh on shell. 我在外壳上使用ssh在远程服务器上运行一个简单命令。
I am currently logged in myHost01
and i'm running this command on myHost02
我目前登录myHost01
和我在运行此命令myHost02
The expected result is this is a test myHost02
. 预期的结果是this is a test myHost02
。 HOWEVER, I get this is a test myHost01
但是,我得到的this is a test myHost01
This is my command 这是我的命令
sshpass -p root ssh -q root@127.0.0.2 "echo this is a test `hostname`"
I don't know why it is taking the hostname of the server I'm running the command from!!! 我不知道为什么它要使用我从中运行命令的服务器的主机名!
It is also noticeable that when I run this 还值得注意的是,当我运行此
sshpass -p root ssh -q root@127.0.0.2 "hostname"
I get myHost02
(which is the correct output) 我得到myHost02
(这是正确的输出)
Pass the command in single quotes, like below. 用单引号将命令传递,如下所示。 The double quotes cause the shell to execute command substitution hostname
(locally) in-place and pass the resultant string this is a test myHost01
to ssh
双引号使外壳程序就地执行命令替换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.