Last active
June 23, 2016 21:51
-
-
Save pandeybk/a532d30030f0694488bda8e4035cdd81 to your computer and use it in GitHub Desktop.
Reboot system if telnet connection is failed for certain time
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 python | |
import telnetlib | |
import time | |
import os | |
HOST="some.host.com" | |
PORT=22 | |
OKCOUNT=0 | |
FAILEDCOUNT=0 | |
while True: | |
try: | |
telnet = telnetlib.Telnet(HOST,PORT) | |
OKCOUNT+=1 | |
except: | |
FAILEDCOUNT+=1 | |
time.sleep(10) | |
if(FAILEDCOUNT>=6): | |
os.system("/sbin/shutdown -r now") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment