开发者

Paramiko starts a SSH proccess and it dies..why?

Below is my code. When log into the server and I run ps aux | grep python I see all of the process start and then die after a second or two. If I run the command in the server..it works. I have tried with nohup.whithout nohup etc I am out of an explanation. This is a long process that should take hours.

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')
#开发者_如何学JAVAstdin, 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()


Try checking the output of the command. There may be an error been written, and you won't see it with your current code. Try doing:

stdin, stdout, stderr = ssh.exec_command('python /home/ubuntu/Optimization/pvServer2.py')
print 'exit_code: %d' % stdout.channel.recv_exit_status()
print stdout.read()
print stderr.read()

Once you have figured out what is wrong, and fixed it, then you can return to using nohup.

I think what is wrong is the way you are calling the export DISPLAY command. This won't affect the env of the other commands you are running. You need to do something like this:

stdin, stdout, stderr = ssh.exec_command('sh -c "export DISPLAY=localhost:0; python /home/ubuntu/Optimization/pvServer2.py"')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜