Skip to content

Instantly share code, notes, and snippets.

@pandeybk
Last active June 23, 2016 21:51
Show Gist options
  • Save pandeybk/a532d30030f0694488bda8e4035cdd81 to your computer and use it in GitHub Desktop.
Save pandeybk/a532d30030f0694488bda8e4035cdd81 to your computer and use it in GitHub Desktop.
Reboot system if telnet connection is failed for certain time
#!/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