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

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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!
1

linux tee command

php myscript.php | tee log.txt

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.