gpt4 book ai didi

linux - 通过 ssh 运行命令时向远程机器提问

转载 作者:太空宇宙 更新时间:2023-11-04 11:15:16 25 4
gpt4 key购买 nike

我有一些服务器,我想在所有服务器上安装 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

这个语法正确吗?

不起作用。

有什么想法吗?

提前谢谢你

最佳答案

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

关于linux - 通过 ssh 运行命令时向远程机器提问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21361130/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com