asking to questions from remote machine while runn

2019-08-31 06:37发布

I have some servers and I want to install SSL on all of them I wrote the following script(I should run it from each servers):

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

note: I should run script like this(because of assigning ssl certs):

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

now my question: I want to write a bash to do it with numbers of my servers.I wrote something like this(I should run it on my machine):

#!/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

Is this syntax right?

does not work.

any idea?

thank you in advance

标签: linux bash ssl ssh
1条回答
一纸荒年 Trace。
2楼-- · 2019-08-31 07:12

SSH and heredoc

You could'nt make two here-doc on same command line!

But you could write distant ssh command entirely on command line:

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

Note the use of double-quotes!

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
查看更多
登录 后发表回答