break für until-schleife in for schleife
Hallo,
ichhabe folgendes Bash-Script.
Code:
#!/bin/bash
hosts=(129.0.0.2 127.0.0.1)
i=0
for host in $hosts; do
until nc "$host" 5432 -w 7 -v -z
do
echo waiting for postgres to start
sleep 2
((i=i+1))
echo $i
if [ $i -gt 2 ]
then
echo "Connection to postgres host $host could not be established"
break 1
fi
done
done
Hier soll x mal getestet werden, ob eine Verbindung zum host möglich ist. wenn es mehr als x mal nicht funktioniert hat, soll der nächste host probiert werden. leider beendet das break auch die for schleife. wie kann ich das verhindern?
VG niesel