Here's what I'm trying to emulate:
Open two PuTTY windows and connect with auth to the same machine. Run one command (we'll call this CHECK) in window 1 that waits for the other command (we'll call this TEST) that I run in window 2. The CHECK evaluates the TEST and after the TEST is done shows that it passed in CHECK. I then have to CTRL+C out of it.
I'm trying to skip those logins and do it via a GUI so I just push a button.
I've tried calling the TEST script via subprocess and it runs but CHECK just sits there waiting forever. I've tried it the otherway around and the same result.
If stdin, stdout, stderr doesn't show anything in CHECK what does?
I suppose I could put a wait then close on CHECK because the TEST runs for a set amount of time but I need the output of CHECK to see whether it passed or not.
By the way I'm using tkinter for the GUI with one button and when I run the CHECK part it freezes and becomes Not Responsive. Is there anyway to fix that?
My code so far:
import subprocess
import tkinter as tk
import paramiko
hostname = "xxx.xxx.xxx.xxx"
username = "xxx"
password = "xxx"
def initiate():
subprocess.call(["python", "ljustest2.py"])
client1 = paramiko.SSHClient()
client1.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client1.connect(hostname=hostname, username=username, password=password)
print('Connect 1')
except:
print("[!] Cannot connect to the SSH Server")
exit()
commands = ['mosquitto_sub -t "/test/#" -v']
for command in commands:
print("="*40, command, "="*40)
stdin, stdout, stderr = client1.exec_command(command)
print(stdout.read().decode())
err = stderr.read().decode()
if err:
print(err)
window = tk.Tk()
window.title("MQTT")
window.geometry("300x300")
window.resizable(False, False)
window.rowconfigure([0], minsize=300, weight=0)
window.columnconfigure([0], minsize=300, weight=0)
btn_abl = tk.Button(window, text="Start", command = initiate)
btn_abl.grid(row=0, column=0, sticky="nsew")
window.mainloop()
The code for ljustest2.py:
import paramiko
hostname = "xxx.xxx.xxx.xxx"
username = "xxx"
password = "xxx"
client2 = paramiko.SSHClient()
client2.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client2.connect(hostname=hostname, username=username, password=password)
print('Connect 2')
except:
print("[!] Cannot connect to the SSH Server")
exit()
commands = ['mosquitto_pub -t "/test/start" -m \'{"type": "phcomtest", "cycles": 3}\'']
for command in commands:
print("="*40, command, "="*40)
stdin, stdout, stderr = client2.exec_command(command)
print(stdout.read().decode())
err = stderr.read().decode()
if err:
print(err)