1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/bin/bash for i in 1 1 2 2 3 1; do < <(ip route show default) read -r _ _ ip _ if [ -n "$ip" ]; then echo "Trying to ping $ip" ping -W 2 -c 1 "$ip" &> /dev/null && exit 0 else echo "No default gateway yet..." fi sleep "$i" done exit 1