cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
346
Views
0
Helpful
0
Comments
RajasaravananS
Level 3
Level 3
import paramiko
from paramiko import ssh_exception
import time
 
 
 
def rebootserver():
with open('C:PATH',"r") as cred:
for mycred in cred:
print(mycred)
usrcred = mycred.split('\t')
host = usrcred[0]
user = usrcred[1]
passw = usrcred[2]
   
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
print(host, user, passw)
ssh.connect(hostname=host, username=user, password=passw,timeout=120)
#shell = ssh.exec_command(command="show status",bufsize=10000,get_pty=True)
shell = ssh.invoke_shell()
print('\n'+time.strftime("%m/%d/%Y %H:%M:%S"))
time.sleep(40)
shell.send("utils system restart\n")
time.sleep(5)
shell.send("y")
time.sleep(2)
shell.send("e")
time.sleep(2)
shell.send("s\n")
time.sleep(10)
print('\n'+time.strftime("%m/%d/%Y %H:%M:%S"))
buffer = shell.recv(10240)
myout = shell.recv(10240).decode('utf-8')
 
#we can add a logic here to check the if the reboot was successful and reattempt by looking for a keyword in str(myout)
print(str(buffer))
time.sleep(600)
 
except ssh_exception as err:
print(err)
 
 
 
rebootserver()

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: