Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send output to file from within shell script

Tags:

shell

unix

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

like image 991
Buzkie Avatar asked Mar 09 '10 16:03

Buzkie


1 Answers

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 go into the file output.txt.

like image 121
codaddict Avatar answered Oct 13 '22 22:10

codaddict