How to log output in bash and see it in the terminal at the same time? How to log output in bash and see it in the terminal at the same time? linux linux

How to log output in bash and see it in the terminal at the same time?


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.


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)


another option is to use block based output capture from within the script (not sure if that is the correct technical term).

Example

#!/bin/bash {  echo "I will be sent to screen and file"  ls ~} 2>&1 | tee -a /tmp/logfile.logecho "I will be sent to just terminal"

I like to have more control and flexibility - so I prefer this way.