Guest User

Untitled

a guest
Dec 10th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. a = ['backup ', 'complete']
  2. output= "backup is not complete"
  3.  
  4. if all(x in str for x in a):
  5.  
  6. print "im here"
  7.  
  8. else:
  9. print "im not"
  10.  
  11.  
  12.  
  13. import datetime, time
  14. from time import sleep
  15. from Tkinter import *
  16. import paramiko
  17. def backup():
  18. canvas = Canvas(page3, relief = FLAT, background = "#D2D2D2", width = 694, height = 120)
  19. canvas.pack()
  20. txtOutput = Text(canvas, wrap = NONE, height =14, width = 86, borderwidth=2)
  21. txtOutput.pack()
  22. try:
  23. ssh = paramiko.SSHClient()
  24. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  25. ssh.connect(server, port=22, username='user', password='pass')
  26. channel = ssh.invoke_shell()
  27.  
  28. except paramiko.AuthenticationException:
  29. print("Authentication failed, please verify your credentials: %s")
  30. except paramiko.SSHException as sshException:
  31. print("Unable to establish SSH connection: %s" % sshException)
  32. except paramiko.BadHostKeyException as badHostKeyException:
  33. print("Unable to verify server's host key: %s" % badHostKeyException)
  34. except Exception as e:
  35. print(e.args)
  36.  
  37. command = ['command1','command2','command3','command4','command5','command6','command7','command8']
  38.  
  39. def send_cmd(i):
  40. if i == 6:
  41. print("**Backup started**")
  42. channel.send(command[i]+'n')
  43. check2()
  44. else:
  45. print(command[i] + "command has started**")
  46. channel.send(command[i]+'n')
  47. check1(i)
  48.  
  49.  
  50. def check1(i):
  51. if not channel.recv_ready():
  52. txtOutput.after(3000, check1, i) # wait 3s and re-check
  53. else: # server is ready, wait for execution to end and fetch output
  54. txtOutput.after(1000, get, command[i] + "command has ended**", i)
  55.  
  56.  
  57. def check2():
  58. if not channel.recv_ready():
  59. txtOutput.after(10000, check2) # wait 3s and re-check
  60. else: # server is ready, wait for execution to end and fetch output
  61. txtOutput.after(240000, get, "**Backup completed**", 6)
  62.  
  63. def get(msg, i):
  64. print(msg)
  65. output = channel.recv(9999) #read in
  66. print(output.decode('utf-8'))
  67. txtOutput.insert(END, output.decode('utf-8'))
  68. if i < len(command) - 1:
  69. send_cmd(i + 1) # launch next command
  70. else: # no more command to launch, close ssh
  71. ssh.close()
  72.  
  73. send_cmd(0)
Add Comment
Please, Sign In to add comment