Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

How wait for eth0 interface before running “ip link”, “ip addr” and “ip route” commands?

General Tech Bugs & Fixes

Max. 2000 characters
Replies

usr_profile.png

User

( 6 months ago )

 

I have the following script that I need to run on my Synology NAS at boot-up. The Synology NAS has built-in scheduled tasks with the ability to trigger tasks at boot-up.

The script I need to run is this:

#!/bin/sh

ip link add macvlan0 link eth0 type macvlan mode bridge
ip addr add 192.168.0.240/32 dev macvlan0
ip link set macvlan0 up
ip route add 192.168.0.240/28 dev macvlan0

However, this does not work, the task seems to trigger to soon when the eth0 interface is not yet ready to accept these commands.

Placing a sleep 60 before all ip * commands, solves the issue. But it doesn't feel right to wait an arbitrary amount of seconds before doing my thing.

Given my requirements above, what's the best method to wait for the eth0 interface to be available so that I can execute ip * commands?

usr_profile.png

User

( 6 months ago )

Here's the solution I eventually solved my problem with:

while ! ip link show eth0 | grep -q 'state UP'; do
    sleep 1
done

ip link add macvlan0 link eth0 type macvlan mode bridge
ip addr add 192.168.0.240/32 dev macvlan0
ip link set macvlan0 up
ip route add 192.168.0.240/28 dev macvlan0

However, I had 2 "boot-up" scheduled tasks on my Synology and I was getting some errors at boot-up. To solve that issue I configure this task to have the other one as pre-task. In other words, the tasks executed in sequence, waiting for the previous task to finish before starting the new one.

what's your interest


forum_ban8_5d8c5fd7cf6f7.gif