Created
September 22, 2011 09:54
-
-
Save moretea/1234444 to your computer and use it in GitHub Desktop.
Restart the networking stack if the wifi connection has died
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
| #!/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