M
M
m0Hze2015-02-10 19:05:17
PHP
m0Hze, 2015-02-10 19:05:17

Running python script in background?

Good evening! The essence of the problem.
There is a php script that communicates with another server via SSH using the phpseclib library.
There was a need to run a python script on a remote server from SSH.
I wrote this code, and I thought that everything would be ok:

$ssh->exec("nohup python ./script.py --params=1  >/dev/null 2>&1");

But, the script from which I send this command hangs, waiting for the execution of this command on the server. The python script itself can be executed for days, that is, I will not wait for an answer.
how to build a command that does the same thing (runs a script in the background, allows you to close the connection), and does not make php wait for a response. I hope I made it clear, if anything, I'm always ready to add.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
Ivan, 2015-02-10
@SpinenkoIA

Usually they do this in the console:
ssh [email protected]_ip 'you command &'
And that's it & puts the command in the background, ssh returns control

S
Sergey Petrikov, 2015-02-10
@RicoX

Try using screen as a layer, or in your case, you need to run another script that will already run nohup python ./script.py --params=1 >/dev/null 2>&1

V
Vlad Zhivotnev, 2015-02-11
@inkvizitor68sl

If in shell terms, then you need to do this:
ssh host "/path/to/python/script.py & bash" Translate
into python yourself)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question