Last active
October 3, 2019 09:12
-
-
Save unixfox/3db7bbe9074dfed88d99377811478087 to your computer and use it in GitHub Desktop.
Network Manager PPPoe connection watcher
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
[Unit] | |
Description=NetworkManager Watcher | |
Wants=NetworkManager-wait-online.service | |
After=NetworkManager-wait-online.service | |
[Service] | |
ExecStart=/usr/local/bin/nm-watcher | |
[Install] | |
WantedBy=multi-user.target |
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/bash | |
while true; do #create a infinite loop to keep looking at your connection | |
NET=$(ifconfig ppp0 | grep "inet") # verify if the interface has an assigned IP | |
ROUTE=$(fping -r 10 -t 20000 google.com 2>&1 | grep "alive") # try to ping google.com and verify if we have any response | |
WEB=$(wget --tries=50 --timeout=500 --spider http://whatismyip.akamai.com 2>&1 | grep "OK") # spiders google.com to verify if the page exists. returns error if a connections is not possible | |
if [ ! "$NET" != "" ] || [ ! "$ROUTE" != "" ] || [ ! "$WEB" != "" ]; then # verify if any of the above conditions aren't OK | |
while ! fping -I eth0 8.8.8.8 &> /dev/null | |
do | |
echo "[WARN] Lost main internet connection" | |
sleep 10s | |
done | |
echo "[WARN] Trying to reconfigure Network Manager" | |
echo $NET | |
echo $ROUTE | |
echo $WEB | |
systemctl daemon-reload | |
systemctl restart NetworkManager | |
sleep 10m | |
fi | |
sleep 120s | |
done |
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/bash | |
#/etc/NetworkManager/dispatcher.d/pppdetect | |
if [[ $1 == "ppp0" ]] && [[ $2 == "down" ]]; then | |
/usr/bin/systemctl start ppp-watcher | |
/usr/bin/systemctl restart NetworkManager NetworkManager-wait-online | |
fi | |
if [[ $1 == "ppp0" ]] && [[ $2 == "up" ]]; then | |
/usr/bin/systemctl stop ppp-watcher | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment