T
T
Timur2014-06-28 23:12:56
linux
Timur, 2014-06-28 23:12:56

PHP CLI. How to run a script from a terminal via SSH, close the terminal, and then open it again and see the progress?

Hello!
I have a remote server on debian, to which I connect via SSH and run one php script from the console, which can run for several hours. The script through echo displays information about the progress and processing of some data. Is it possible to somehow run the script, close the terminal, and then, after a while, open the terminal again and see the progress (see what the script is currently outputting)?
I launch the script as follows.
php script.php
Of course, I can write logs to a file or output to a file,
php script.php > script.txt
but in this case, as I understand it, the file will be occupied by the application until it is written to the end. And if it doesn’t, then I won’t be able to see its changes in real time (I think it’s possible. But I don’t know how)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
M
malerix, 2014-06-28
@XAKEPEHOK

screen and tmux. Here is the finished recipe for you .
How it works (roughly):

$ ssh localhost
$ screen
запускается процесс screen, в нём bash или что-нибудь ещё.
Запускаете вашу команду:
$(screen) php script.php
нажимаете Ctrl+A, Ctrl+D. Попадаете обратно в первый шелл.
отключаемся
$ exit
пьём кофе.
подключаемся вновь:
$ ssh localhost
$ screen -r
Видим результат работы нашей команды и приглашение ввести новую.
$(screen)

The rest is described in the man screen.

V
Vladimir Abramov, 2014-06-28
@kivsiak

man screen

A
Alexander Melekhovets, 2014-06-29
@Blast

Alternatively, run the script through nohup, then it will not be tied to the terminal.
You can monitor in real time the addition of lines to a file throughtail -f file.log

S
Sergey Pribylskiy, 2014-06-29
@ASP

I advise you to look at the tmux line (similar to screen)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question