在bash中继续之前,等待网络链接启动

在bash中继续之前,等待网络链接启动,bash,networking,ping,ifconfig,Bash,Networking,Ping,Ifconfig,在继续之前,是否有方法检查bash脚本中多个接口的网络接口链接是否成功 比如: eth0 eth1 eth2 eth3 network interfaces are brought up Wait for link detection on all 4 interfaces Proceed if [ $( ifconfig -s | grep eth0 ) ]; then echo "eth0 is up!" 运行ifconfig-s后,您可以检查网络接口的名称是否出现 比如: eth0 e

在继续之前,是否有方法检查bash脚本中多个接口的网络接口链接是否成功

比如:

eth0 eth1 eth2 eth3 network interfaces are brought up
Wait for link detection on all 4 interfaces
Proceed
if [ $( ifconfig -s | grep eth0 ) ]; then echo "eth0 is up!"

运行
ifconfig-s
后,您可以检查网络接口的名称是否出现

比如:

eth0 eth1 eth2 eth3 network interfaces are brought up
Wait for link detection on all 4 interfaces
Proceed
if [ $( ifconfig -s | grep eth0 ) ]; then echo "eth0 is up!"
查看更多详细信息


要继续进行此测试,您可以执行@jm666所说的操作:

while ! ping -c 1 -W 1 1.2.3.4; do
    echo "Waiting for 1.2.3.4 - network interface might be down..."
    sleep 1
done

在一个循环中,每秒尝试1x ping到每个网络中的某个已知主机,或者检查ifconfig输出…如果它们启动,并不一定意味着其他主机响应ping。如果我只想测试一次,这很好,但是,如果我需要主动等待,直到它上线,然后再继续呢?为什么在那里有一个
-W
标志?您没有为单个ping指定超时…
-c1-w1
表示“尝试1个echo,最多等待1秒”。如果未接收回显,则进入If块,显示消息,并等待一秒钟后重试。如果未指定
-W 1
。。。要等多久?我在手册页中没有看到描述,据我所知,
-c1
只会发送一个回音,并等待它返回,不管需要多长时间。添加
-W 1
可以防止等待时间过长,只需1秒即可获得响应。