Created
December 12, 2016 05:22
-
-
Save istepanov/a1d706fb48138795c0ab0d7e50f39bbc to your computer and use it in GitHub Desktop.
Revisions
-
istepanov created this gist
Dec 12, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ #!/usr/bin/env python import os import datetime address = '8.8.8.8' ping_timeout = 5 attempts = 4 log_file = '/var/log/ping_test.log' failed_attempts = 0 for i in range(0, attempts): result = os.system('/bin/ping -c 1 -w %i %s > /dev/null 2>&1' % (ping_timeout, address)) if result != 0: failed_attempts += 1 if failed_attempts == attempts: with open(log_file, 'a') as logfile: now = datetime.datetime.now().strftime('%Y-%m-%d %H:%M') logfile.write("%s 'ping %s' failed attempts: %i. Rebooting...\n" % (now, address, failed_attempts)) os.system('/sbin/reboot')