import subprocess
host_list = ['host']
def main():
print("Running latency check")
for item in host_list:
host = ''.join(item)
connect_to_host(host)
def connect_to_host(host):
print(host)
ssh = subprocess.Popen(['ssh', '-o', 'ConnectionAttempts=3', host], shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for ssh_line in iter(ssh.stdout.readline, ""):
yield ssh_line
ssh.stdout.close()
get_legend = subprocess.Popen(['command'], shell=True,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for get_legend_line in iter(get_legend.stdout.readline, ""):
yield get_legend_line
get_legend.stdout.close()
main()
脚本在第一个功能上停止,只需打印“运行延迟检查”