# -*- coding: utf-8 -*- import time import paramiko c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False) cmd = ( "systemctl start douyinweb-api douyinweb-web; sleep 5; " "systemctl is-active douyinweb-api douyinweb-web; " "curl -s -o /dev/null -w 'api=%{http_code}\\n' http://127.0.0.1:8014/api/health; " "curl -s -o /dev/null -w 'web=%{http_code}\\n' http://127.0.0.1:4015/slots; " "systemctl status douyinweb-web --no-pager -l | head -n 25" ) chan = c.get_transport().open_session() chan.settimeout(90) chan.get_pty() chan.exec_command(cmd) buf = [] while True: if chan.recv_ready(): buf.append(chan.recv(65535).decode("utf-8", "replace")) if chan.exit_status_ready() and not chan.recv_ready(): break time.sleep(0.25) while chan.recv_ready(): buf.append(chan.recv(65535).decode("utf-8", "replace")) print("".join(buf)) c.close()