0

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

chiliNUT
  • 18,989
  • 14
  • 66
  • 106

2 Answers2

2

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.

bishop
  • 37,830
  • 11
  • 104
  • 139
  • This is exactly what I needed. I think someone mentioned `tee` to me before regarding some other issue I was having, and it didn't work and they didn't explain what `tee` is used for. This answered my question and gave a very clear and concise explanation for `tee`. Thanks! – chiliNUT Aug 07 '14 at 03:37
1

linux tee command

php myscript.php | tee log.txt