views:

63

answers:

3

I'm creating a script for users to run. I need to redirect the output to a file I'm creating from inside the script (hostname-date).

I have all the pieces except for how to copy the output of the script from inside the same script. All the examples I can find call the script and > it into the log, but this isn't an option.

-Alex

+1  A: 

exec in bash allows you to permanently redirect a FD (say, stdout) to a file.

Ignacio Vazquez-Abrams
A: 

A shell that calls a shell.

Have the first shell create the variable (hostname-date) and call the second shell redirecting the output to the file.

sparkkkey
+2  A: 

Add the following at the top of your script:

exec &> output.txt

It will make both stdin and stderr of the commands in the rest of your script into the file output.txt.

codaddict
can I use that with tee to sent it to the console too?
Buzkie