Guest User

Untitled

a guest
Jan 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. STDOUT.sync=true
  3.  
  4. CHECK_HOST = "google.nl"
  5.  
  6. def check_connection
  7. system("ping #{CHECK_HOST} -c 5 1> /dev/null 2>/dev/null")
  8. return true if $? == 0
  9. end
  10.  
  11. loop do
  12. print "[#{Time.now.to_s}] Checking connection (check if #{CHECK_HOST.inspect} is accessible) ... "
  13. if check_connection
  14. print " Connection OK."
  15. else
  16. print " Connection broken! Restarting network ... "
  17. `service network-manager restart`
  18. print " restarted. Sleep 10 extra seconds. "
  19. sleep 10
  20. end
  21.  
  22. puts "Sleeping 5 seconds"
  23. sleep 5
  24. end
Add Comment
Please, Sign In to add comment