Guest User

Untitled

a guest
Jun 12th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. import SSH
  2. from tkinter import *
  3.  
  4. hostname = 'blah'
  5. username = 'blah'
  6. password = 'blah'
  7.  
  8. class mymain:
  9.  
  10. def __init__(self, master):
  11. self.master = master
  12. master.title("Bunch of GUI stuff that doesn't matter for this issue")
  13.  
  14. def ver92(self):
  15. connection = SSH.SSH(hostname, username, password)
  16. connection.sendCommandOld('cd {}/xxx/xx/ && source .cshrc && cd xxx/xxxx/xxx/ && ./bashscriptname'.format(path), var1, var2, var3)
  17.  
  18. from paramiko import client
  19. class SSH:
  20. client = None
  21.  
  22. def __init__(self, address, username, password):
  23. print("Login info sent.")
  24. print("Connecting to server.")
  25. self.client = client.SSHClient() # Create a new SSH client
  26. self.client.set_missing_host_key_policy(client.AutoAddPolicy())
  27. self.client.connect(address, username=username, password=password, look_for_keys=False) # connect
  28.  
  29. def sendCommandOld(self, command, var1, var2):
  30. print("Sending your command")
  31. # Check in connection is made previously
  32. if (self.client):
  33. stdin, stdout, stderr = self.client.exec_command(command)
  34. stdin.write(var1 + 'n') # get input to bash
  35. stdin.write(var2 + 'n')
  36. stdin.flush()
  37. while not stdout.channel.exit_status_ready():
  38. # Print stdout data when available
  39. if stdout.channel.recv_ready():
  40. # Retrieve the first 1024 bytes
  41. alldata = stdout.channel.recv(2048)
  42. while stdout.channel.recv_ready():
  43. # Retrieve the next 1024 bytes
  44. alldata += stdout.channel.recv(1024)
  45.  
  46. # Print as string with utf8 encoding
  47. print(str(alldata, "utf8"))
  48.  
  49. print('stdout: ', stdout.read())
  50. print('stderr: ', stderr.read())
  51.  
  52. else:
  53. print("Connection not opened.")
Add Comment
Please, Sign In to add comment