Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try:
- ssh = paramiko.SSHClient()
- ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
- ssh.connect(server, port=22, username='user', password='pass')
- channel = ssh.invoke_shell()
- except paramiko.AuthenticationException:
- print("Authentication failed, please verify your credentials: %s")
- except paramiko.SSHException as sshException:
- print("Unable to establish SSH connection: %s" % sshException)
- except paramiko.BadHostKeyException as badHostKeyException:
- print("Unable to verify server's host key: %s" % badHostKeyException)
- except Exception as e:
- print(e.args)
- #array of commands
- command = ['command1','command2','command3','command4','command5','command6','command7']
- progress["value"] = 0
- progress["maximum"] = len(command)
- i=0
- for commands in command:
- if i == 6:
- channel.send(command[i]+'n')#display command and press enter
- print("**Backup started**")
- while not channel.recv_ready():#Wait for the server to read and respond
- time.sleep(10)
- time.sleep(240)
- print("**Backup completed**")
- output2 = channel.recv(9999)
- print(output2.decode('utf-8'))
- bytess += 1
- progress["value"] = bytess
- txtOutput.insert(END,output2)
- txtOutput.update_idletasks()#update the output one line at time
- progress.update_idletasks()
- else:
- channel.send(command[i] + 'n')
- print(commands + "command has started**")#display command and press enter
- while not channel.recv_ready(): #Wait for the server to read and respond
- time.sleep(3)
- time.sleep(1)
- print(commands + "command has ended**")#wait enough for writing to (hopefully) be finished
- output = channel.recv(9999) #read in
- print(output.decode('utf-8'))
- time.sleep(0.2)
- bytess += 1
- progress["value"] = bytess
- txtOutput.insert(END,output.decode('utf-8'))
- txtOutput.update_idletasks()#update the output one line at time
- progress.update_idletasks()
- i+=1
- print("Completed we will now close connection!!")
- ssh.close()
Add Comment
Please, Sign In to add comment