wait-for-routes 582 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/sh
  2. #
  3. # Wait for routing adjacencies to come up and produce a default route
  4. #
  5. # Maximilian Wilhelm <max@sdn.clinic>
  6. # -- Mon, 05 Apr 2021 02:31:58 +0200
  7. # Wait for this amount of seconds before giving up
  8. timeout=30
  9. # Wait for IPv4 default route to emerge
  10. (
  11. for n in $(seq 1 $timeout); do
  12. if ip -4 route | grep -q "^default"; then
  13. break
  14. fi
  15. sleep 1
  16. done
  17. )&
  18. # Wait for IPv6 default route to emerge
  19. (
  20. for n in $(seq 1 $timeout); do
  21. if ip -6 route | grep -q "^default"; then
  22. break
  23. fi
  24. sleep 1
  25. done
  26. )&
  27. # WAit for both sub-shells to finish
  28. wait
  29. exit 0