Skip to content

Instantly share code, notes, and snippets.

@vimalvnair
Last active March 30, 2021 14:25
Show Gist options
  • Save vimalvnair/346a5e7590ae6bb4391f62c52c77003c to your computer and use it in GitHub Desktop.
Save vimalvnair/346a5e7590ae6bb4391f62c52c77003c to your computer and use it in GitHub Desktop.
Monitor network connections and restart it if needed [Raspberry PI]
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