我正在实现一些将通过ssh协议在远程计算机中运行的应用程序。
我已选择paramiko执行ssh连接。
我的虚拟机低于
我正在使用Threading脚本,当我按Ctrl z且Program未终止时。任何可以解决的问题。我认为这可能是错误。.
trigger.py用于执行脚本:
def time_trigger(ip):
"""
Trigger Onboard Deploy
"""
cmd = ""
remote.remote_cmd(ip, cmd)
t1 = threading.Thread(target=time_trigger, args=(ip1,))
t2 = threading.Thread(target=time_trigger, args=(ip2,))
t1.start()
t2.start()
t1.join()
t2.join()
remote.py脚本用于建立远程ssh连接:
import paramiko
import os
from paramiko import SSHClient
from scp import SCPClient
class Remote:
def __init__(self, username, password, port):
self.port = port
self.user = username
self.password = password
def createSSHClient(self, server):
client = paramiko.SSHClient()
client.load_system_host_keys()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(server, self.port, self.user, self.password)
return client
def remote_cmd(self, hostname, command):
try:
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(hostname, port=self.port, username=self.user, password=self.password)
stdin, stdout, stderr = client.exec_command(command)
print stdout.read()
finally:
client.close()
time1.py(等待5分钟):
import time
time.sleep(300)
我正在使用Python 2.7