How wait for eth0 interface before running "ip link", "ip addr" and "ip route" commands?
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.
Check the status of eth0
from /sys/class/net/eth0/operstate
and wait until the network interface to be up:
while ! [ "$(cat /sys/class/net/eth0/operstate)" = "up" ]
do
echo "waiting for eth0 to be up"
sleep 2
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