【发布时间】:2017-12-08 01:52:21
【问题描述】:
我有一个脚本,它从 /etc/hosts 文件中读取主机 IP,执行 ssh 并更新给定用户的密码。但是,脚本在为第一台主机设置密码后关闭,无法为其余主机设置密码。请找到以下文件-
/etc/hosts文件-
172.x.x.x 主机1
172.x.x.x 主机2
172.x.x.x 主机3
我使用的脚本是 as-
key=$1
user=$2
password=$3
filename='/etc/hosts'
while IFS= read -r line; do
IFS=' ' read -r -a array <<< $line
ssh -i $key centos@${array[0]} "echo "$password" | sudo passwd $user --stdin"
done <$filename
脚本很简单。但是在从文件中为host1 设置密码后它正在关闭。有谁知道我错过了什么?
【问题讨论】:
标签: linux bash ssh while-loop