我试图在多台计算机上运行一个命令,但是这个命令几乎立即开始然后结束。它需要一段时间来运行,所以我只想启动,然后转到下一台计算机。在
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
un = 'username'
pw = 'password'
version = None
count = 0
for i in xrange(1):
host = 'hydra' + str(i) + '.eecs.utk.edu'
try:
conn = client.connect(host, username=un, password=pw)
except:
continue
count += 1
stdin, stdout, stderr = client.exec_command('ls ./neuro/networks/anets/')
#gets highest numbered folder to compute next version
if version == None:
version = max(map(int, stdout.read().split())) + 1
anew = 'mkdir ~/neuro/networks/anets/{}'.format(version)
bnew = 'mkdir ~/neuro/networks/bnets/{}'.format(version)
#this is the command that ends too early
net = 'nice -n 19 ~/neuro/apps/polebalance/bin/PBEO > ~/neuro/networks/anets/{v}/net{pc:02d}_{v}.txt'.format(v=version, pc=i)
print '.../anets/{v}/net{pc:02d}_{v}.txt'.format(v=version, pc=i)
stdin, stdout, stderr = client.exec_command(anew)
stdin, stdout, stderr = client.exec_command(bnew)
stdin, stdout, stderr = client.exec_command(net)
client.close()
print 'making {} nets'.format(count)
有人知道如何启动进程,然后在进程不终止的情况下终止会话吗?在
您可以使用}。在
nohup
运行命令来禁用挂断信号,并以&
结束该命令以在后台运行。现在您的ssh可以退出并继续运行。创建目录时,您应该等待exec_command
完成,以防系统有一段时间运行缓慢。我把这两个品牌合并成一个,所以只有一个等待。除此之外,我只在net命令中添加了nohup
和{更新
这个测试程序通过ssh在本地计算机上运行。每个远程命令都写入日志文件,我们读取该文件以确保其正常工作。在
^{pr2}$在我的机器上结果是
相关问题 更多 >
编程相关推荐