import paramiko
import time hostname = '192.168.248.156'
port = 22
user = 'zhou'
passwd = '' paramiko.util.log_to_file('paramiko.log')
s = paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname=hostname, port=port, username=user, password=passwd) #get time before reboot
stdin, stdout, stderr = s.exec_command('date', timeout=5)
print "time before reboot:" + stdout.readline() #reboot
stdin, stdout, stderr = s.exec_command('reboot', timeout=5)
stdin.write('')
stdin.flush() for i in range(10):
s.connect(hostname=hostname, port=port, username=user, password=passwd)
time.sleep(30) stdin, stdout, stderr = s.exec_command('date', timeout=5)
print "time after reboot:" + stdout.readline() s.close()