Last active
March 30, 2021 14:25
-
-
Save vimalvnair/346a5e7590ae6bb4391f62c52c77003c to your computer and use it in GitHub Desktop.
Monitor network connections and restart it if needed [Raspberry PI]
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
def ping host | |
system("ping -c 1 #{host}") | |
end | |
loop do | |
sleep 60 | |
unless ping('google.com') || ping('facebook.com') || ping('wikipedia.org') | |
`sudo ifconfig eth0 down` | |
sleep 5 | |
`sudo ifconfig eth0 up` | |
end | |
unless ping('10.8.0.1') | |
`sudo systemctl restart openvpn` | |
end | |
sleep 300 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment