Last active
April 21, 2020 12:09
-
-
Save t-davies/5d69c15c3d53a2bb05e9ab892d3c55e7 to your computer and use it in GitHub Desktop.
Watches a *nix network interface for status changes
This file contains 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/bash | |
watch_for_interface() | |
{ | |
if (ifconfig "$1" | grep -q "status: active") | |
then | |
echo "[$1] state changed: active" | |
echo "...do stuff here..." | |
else | |
echo "[$1] state changed: inactive" | |
fi | |
} | |
INTERFACE=en0 | |
export -f watch_for_interface | |
export INTERFACE | |
(echo -e "n.add State:/Network/Interface/${INTERFACE}/IPv4\nn.watch" & cat) | \ | |
scutil | \ | |
awk '/notification/ {system("watch_for_interface $INTERFACE")}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment