我远程服务器上使用的shell中,运行一个简单的命令。命令执行外壳
我目前登录myHost01
和我在myHost02
预期的结果运行此命令是this is a test myHost02
。不过,我得到this is a test myHost01
这是我的命令
sshpass -p root ssh -q [email protected] "echo this is a test `hostname`"
我不知道为什么它走的是服务器的主机名,我从运行命令!
这也是值得注意的是,当我运行这个
sshpass -p root ssh -q [email protected] "hostname"
我得到myHost02
(这是正确的输出)
,只是:'SSH ..... @ ...“$ {command}”'。例如:'command = hostname; ssh ........ @ ....“$ {command}”'。注意,它可以很容易地得到TRICKY ...有时最好是1)创建一个本地'the_script'脚本,和2)'scp the_script user @ remotehost:/ tmp/safe_name' 3)'ssh user @ remotehost“/ tmp/safe_name“'。 safe_name是目标机器上唯一的名称。请注意:其他人可以替换safe_name(尤其是在/ tmp!内)。而在这些做法许多其他潜在的安全漏洞...... –