我有一个快速脚本在每个使用ssh的服务器上运行命令(我确信有很多更好的方法可以做到这一点,但它的目的只是快速工作!!)。对于test1等,没有服务器,所以脚本继续,如果pubkey认证失败,脚本也会继续。但是,如果脚本连接,日期打印,但ssh循环终止...在我的bash循环在一些服务器的列表中,如果ssh连接bash脚本退出
#!/bin/bash -x
cat <<EOF |
##file servers
test1
test2
server1
server2
EOF
while read line
do
if [ "${line:0:1}" != "#" ]; then
ssh -q -oPasswordAuthentication=no -i id_dsa [email protected]${line} date
fi
done
echo read line must have exited
输出是这样的;
+ cat
+ read line
+ '[' t '!=' '#' ']'
+ ssh -q -oPasswordAuthentication=no -i id_dsa [email protected] date
+ read line
+ '[' t '!=' '#' ']'
+ ssh -q -oPasswordAuthentication=no -i id_dsa [email protected] date
+ read line1
+ '[' s '!=' '#' ']'
+ ssh -q -oPasswordAuthentication=no -i id_dsa [email protected] date
Fri Jul 9 09:04:16 PDT 2010
+ read line
+ echo read line must have exited
read line must have exited`enter code here`
与成功返回的ssh命令有关的事情是搞乱了循环或var的条件...有什么建议,为什么?
欢呼声。测试,并去! – 2010-07-09 16:37:59