在继续使用 bash 之前等待网络链接建立

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24962839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:57:25  来源:igfitidea点击:

Waiting for network link to be up before continuing in bash

bashnetworkingpingifconfig

提问by user1527227

Is there a way to check for successful network interface link for multiple interfaces in a bash script before continuing?

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

Something like:

就像是:

eth0 eth1 eth2 eth3 network interfaces are brought up
Wait for link detection on all 4 interfaces
Proceed

回答by jimm-cl

You can check if the network interfaces' names appear after running ifconfig -s.

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

Something like:

就像是:

if [ $( ifconfig -s | grep eth0 ) ]; then echo "eth0 is up!"

Check this linkfor more details.

查看此链接了解更多详情。



To make this test ongoing, you can do something like what @jm666 said:

要进行此测试,您可以执行类似于@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