Hi
I have a shell script that does a whole bunch of things. For the sake of simplicity, assume it runs commands one two and three. What i ultimately need is the ability to display the output of the entire script on the screen as well as capture the output in a file. When I try to do it in the following way, it only captures the output of command three:
command one
command two
command three 2>&1 | tee /tmp/log.txt'
This does not resolve my issue. So I thought of including all commands in a function and then trying to capture the output in a file, like the example given below. This seems to be erroneous
Since I have multiple commands to execute, if I
Func()
{
command one
command two
command three
}
#main
Func 2>&1 | tee /tmp/log.txt'
Is there a way/better way of doing this? Please advice.
Thanks
---------- Post updated at 11:10 AM ---------- Previous update was at 09:49 AM ----------
I found a working solution. After each command that needs to be logged, add 2>&1 | tee -a /tmp/log.txt. It will log on the console and also append it to the log file. Any improvements/more efficient ways of doing it are welcome.