Created
February 6, 2017 22:22
-
-
Save carlashley/5c64731cbcc479adb8be15d7fc895394 to your computer and use it in GitHub Desktop.
Get the active interface for a given route
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Get network interface. We sleep so that the interface has a chance to come up! | |
# Substitute the 0.0.0.0 address if you have a specific route that you want to test, however this may impact | |
# portability if a machine spends more time without access to that route than with. | |
# Give the interface a chance to come up - useful if this is used in any boot up processes | |
while [ $(route get 0.0.0.0 2>/dev/null | grep -c interface) != 1 ]; do | |
sleep 5 | |
done | |
# Actual interface | |
interface=$(route get 0.0.0.0 2>/dev/null | awk '/interface: / {print $2}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment