views:

38

answers:

2

I have some scripts where I need to see the output and log the result to a file, with the simplest example being:

$ update-client > my.log

I want to be able to see the output of the command while it's running, but also have it logged to the file. I also log stderr, so I would want to be able to log the error stream while seeing it as well.

+5  A: 
update-client 2>&1 | tee my.log

2>&1 redirects standard error to standard output, and tee sends its standard input to standard output and the file.

Matthew Flaschen
You can also append the log file, as explained here, and do other stuffs with tee: http://linux.101hacks.com/unix/tee-command-examples/
thegeek
A: 

Just use tail to watch the file as it's updated. Background your original process by adding & after your above command After you execute the command above just use

$ tail -f my.log

It will continuously update. (note it won't tell you when the file has finished running so you can output something to the log to tell you it finished. Ctrl-c to exit tail)

Cfreak
wow tough crowd on this one. What exactly is wrong with this answer?
Cfreak
It's thousands of times worse than using `tee` in my opinion.
Kristopher Ives