在继续bash之前等待网络链接

use*_*227 7 bash networking ping ifconfig

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

就像是:

eth0 eth1 eth2 eth3 network interfaces are brought up
Wait for link detection on all 4 interfaces
Proceed
Run Code Online (Sandbox Code Playgroud)

jim*_*-cl 17

您可以检查运行后是否显示网络接口的名称ifconfig -s.

就像是:

if [ $( ifconfig -s | grep eth0 ) ]; then echo "eth0 is up!"
Run Code Online (Sandbox Code Playgroud)

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


为了使这个测试继续进行,你可以做一些像@ 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
Run Code Online (Sandbox Code Playgroud)