下面的 bash 脚本:
echo "try to ping ${DB_HOST}: ${DB_PORT}";
while ! nc -z ${DB_HOST} ${DB_PORT}; do
echo "try to ping ${DB_HOST}: ${DB_PORT} fail";
sleep 3;
done
nc -z ${DB_HOST} ${DB_PORT} 成功连同远程主机的时候,返回值 是 0, 然后 前面加个 !, 返回值变成1, 不就变成 连同后,无限次尝试下去
我看了下 bash 的文档
Execute consequent-commands as long as test-commands has an exit status of zero. The return status is the exit status of the last command executed in consequent-commands, or zero if none was executed.
while 的条件是 0 的时候,才执行 do 里面的语句,感觉有点奇怪,找大伙确认下
谢谢