Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Waiting for network link to be up before continuing in bash [duplicate]

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

Something like:

eth0 eth1 eth2 eth3 network interfaces are brought up
Wait for link detection on all 4 interfaces
Proceed
like image 651
user1527227 Avatar asked Jul 25 '14 19:07

user1527227


1 Answers

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

Something like:

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

Check this link for more details.


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

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
like image 71
jimm-cl Avatar answered Nov 05 '22 23:11

jimm-cl