【问题标题】:asking to questions from remote machine while running commands over ssh通过 ssh 运行命令时从远程机器询问问题
【发布时间】:2014-01-26 21:58:43
【问题描述】:

我有一些服务器,我想在所有服务器上安装 SSL 我编写了以下脚本(我应该从每个服务器上运行它):

#!/bin/bash
 #something to install SSL on centos
 #....
 #

注意:我应该像这样运行脚本(因为分配了 ssl 证书):

./ssl-conf <<EOF
   > <CountryNmane>
   > <StateName>
   > <LocalityName>
   > <OrganizationName>
   > <OrganizationUnitName>
   > <CommonName> 
   > <EmailAddress>
   > <ChallengePassword>
   > <CompanyName> 
   >EOF

现在我的问题: 我想写一个 bash 来处理我的服务器数量。我写了这样的东西(我应该在我的机器上运行它):

#!/bin/bash
while read pass port user ip; do
    sshpass  -p$pass -o 'StrictHostKeyChecking no' -p $port $user@$ip <<EOF <<SSH
       US
       something
       newyork
       test
       test1
       test2
       test3
       challengepassword
       test4
    EOF #End of asking questions

    #commands to install SSL
    #commands to install SSL
    #commands to install SSL
    SSH #end of commands running on remote machine
done <<___HERE
    mypasswd  22  root  192.168.1.1
    mypasswd  22  root  192.168.1.2
    mypasswd  22  root  192.168.1.3
___HERE

这个语法对吗?

不工作。

有什么想法吗?

提前谢谢你

【问题讨论】:

  • 这有点离题,但您确实应该使用基于密钥的身份验证,而不是允许使用密码进行 root 访问。
  • 没问题..我使用密码变量检查并工作...问题是如何从远程主机提问
  • 你不能在同一行“这里记录”重定向...也就是说,运行 somecommand &lt;&lt;EOF &lt;&lt;SSH 不会做任何有用的事情(它可能会忽略 @ 987654325@).
  • 谢谢///你有什么解决办法吗?

标签: linux bash ssl ssh


【解决方案1】:

SSH 和 heredoc

你不能在同一命令行上创建 两个 here-doc

但是您可以完全在命令行上编写远程ssh 命令:

Script=$'while read foo ;do\n    echo $HOSTNAME $foo\ndone'
echo "$Script"

注意双引号的使用!

while read pass port user ip; do
  sshpass -p$pass ssh -o 'StrictHostKeyChecking no' -p $port $user@$ip "$Script" <<eoparams
    US
    something
    newyork
    test
    test1
    test2
    test3
    challengepassword
    test4
eoparams
done <<eodests
    mypasswd  22  root  192.168.1.1
    mypasswd  22  root  192.168.1.2
    mypasswd  22  root  192.168.1.3
eodests

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-06
    • 2020-10-21
    • 2016-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多