Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SSH
- from tkinter import *
- hostname = 'blah'
- username = 'blah'
- password = 'blah'
- class mymain:
- def __init__(self, master):
- self.master = master
- master.title("Bunch of GUI stuff that doesn't matter for this issue")
- def ver92(self):
- connection = SSH.SSH(hostname, username, password)
- connection.sendCommandOld('cd {}/xxx/xx/ && source .cshrc && cd xxx/xxxx/xxx/ && ./bashscriptname'.format(path), var1, var2, var3)
- from paramiko import client
- class SSH:
- client = None
- def __init__(self, address, username, password):
- print("Login info sent.")
- print("Connecting to server.")
- self.client = client.SSHClient() # Create a new SSH client
- self.client.set_missing_host_key_policy(client.AutoAddPolicy())
- self.client.connect(address, username=username, password=password, look_for_keys=False) # connect
- def sendCommandOld(self, command, var1, var2):
- print("Sending your command")
- # Check in connection is made previously
- if (self.client):
- stdin, stdout, stderr = self.client.exec_command(command)
- stdin.write(var1 + 'n') # get input to bash
- stdin.write(var2 + 'n')
- stdin.flush()
- while not stdout.channel.exit_status_ready():
- # Print stdout data when available
- if stdout.channel.recv_ready():
- # Retrieve the first 1024 bytes
- alldata = stdout.channel.recv(2048)
- while stdout.channel.recv_ready():
- # Retrieve the next 1024 bytes
- alldata += stdout.channel.recv(1024)
- # Print as string with utf8 encoding
- print(str(alldata, "utf8"))
- print('stdout: ', stdout.read())
- print('stderr: ', stderr.read())
- else:
- print("Connection not opened.")
Add Comment
Please, Sign In to add comment