chiliNUT
chiliNUT

Reputation: 19573

View output from a PHP script while it is running and log it to a file, and the script takes human input from STDIN

I have a php script I am running on the command line. It takes ~10 hours or so to complete, so I have it running on a screen so I can detach it, and check its progress throughout its run. I want to also log its output to a file. One solution is to run the script from a screen with

[chiliNUT@server ~]# php myscript.php > log.txt

and then view the live output with

[chiliNUT@server ~]# tail -f ./log.txt

But the only problem is, at points the script requires input from the user via STDIN, so I'm stumped at that part. Typically, the screened script just waits nicely for me to check in and provide input when needed.

How would I be able to

  1. Log the script to a file

  2. And be able to view live output as it is running

  3. And provide input to STDIN when it requires it?

I do not want to modify the original script in any way.

Using php 5.4 and Centos 6.4 Final

Upvotes: 0

Views: 2476

Answers (2)

manbuheiniu
manbuheiniu

Reputation: 11

linux tee command

php myscript.php | tee log.txt

Upvotes: 1

bishop
bishop

Reputation: 39434

Sounds like you might want tee. For example:

php myscript.php | tee log.txt

Basically, tee copies its standard input to the file given on the command line. So you see all the output scrolling by as normal, plus you get the redirection. If you want to append to the log file (rather than overwriting upon tee start), pass the -a flag.

Upvotes: 3

Related Questions