Reputation: 19573
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 screen
ed script just waits nicely for me to check in and provide input when needed.
How would I be able to
Log the script to a file
And be able to view live output as it is running
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
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