import paramiko
import time

hostname = '192.168.248.156'
port = 22
user = 'zhou'
passwd = '123'



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('123')
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()

 

posted on 2017-11-17 01:07  爱编程的小兵  阅读(547)  评论(0编辑  收藏  举报