【发布时间】:2011-09-28 05:03:04
【问题描述】:
下面是我的代码。当登录到服务器并运行 ps aux | grep python 我看到所有的进程都开始了,然后在一两秒后死掉。如果我在服务器中运行命令..它可以工作。我试过 nohup.whithout nohup 等我没有解释。这是一个漫长的过程,需要数小时。
key = paramiko.RSAKey.from_private_key_file(rsa_private_key)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname,port,username=username,pkey=key)
#stdin, stdout, stderr = ssh.exec_command('tar -xf /home/ubuntu/opt.tar.gz')
stdin, stdout, stderr = ssh.exec_command('ls')
#stdin, stdout, stderr = ssh.exec_command(bash)
stdin, stdout, stderr = ssh.exec_command('ls')
stdin, stdout, stderr = ssh.exec_command('export DISPLAY=localhost:0')
stdin, stdout, stderr = ssh.exec_command('nohup python /home/ubuntu/Optimization/pvServer2.py &')
stdin, stdout, stderr = ssh.exec_command('nohup python /home/ubuntu/Optimization/pvServer2.py &')
stdin, stdout, stderr = ssh.exec_command('nohup python /home/ubuntu/Optimization/pvServer2.py &')
stdin, stdout, stderr = ssh.exec_command('python /home/ubuntu/Optimization/pvServer2.py &')
stdin, stdout, stderr = ssh.exec_command('python /home/ubuntu/Optimization/pvServer2.py &')
stdin, stdout, stderr = ssh.exec_command('python /home/ubuntu/Optimization/pvServer2.py &')
stdin, stdout, stderr = ssh.exec_command('python /home/ubuntu/Optimization/pvServer2.py &')
ssh.close()
【问题讨论】:
-
如果你不输入
&(如果你不退出paramiko),它是否还活着? -
不...试过...离开 & 没有帮助。我需要关闭 ssh 连接。
-
& 不会有任何影响,因为它由 shell 处理,例如 sh 或 bash,这里不会使用。