Skip to content

Instantly share code, notes, and snippets.

@moretea
Created September 22, 2011 09:54
Show Gist options
  • Select an option

  • Save moretea/1234444 to your computer and use it in GitHub Desktop.

Select an option

Save moretea/1234444 to your computer and use it in GitHub Desktop.
Restart the networking stack if the wifi connection has died
#!/usr/bin/env ruby
STDOUT.sync=true
CHECK_HOST = "google.nl"
def check_connection
system("ping #{CHECK_HOST} -c 5 1> /dev/null 2>/dev/null")
return true if $? == 0
end
loop do
print "[#{Time.now.to_s}] Checking connection (check if #{CHECK_HOST.inspect} is accessible) ... "
if check_connection
print " Connection OK."
else
print " Connection broken! Restarting network ... "
`service network-manager restart`
print " restarted. Sleep 10 extra seconds. "
sleep 10
end
puts "Sleeping 5 seconds"
sleep 5
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment