1

Currently I am running the bash script like this:

$ myscript.sh param1 param2 param3 >log.txt

and it is outputting the normal information.

My question is:

how can I output all normal and error information (in, out, err) to a log file from within the script itself?

my try is the following but it is not working:

#!/bin/bash
exec 2>&1
{
    mycommand1 
    mycommand2
    mycommand3
} 2>&1 | tee -a /tempfolder
jacky
  • 111

1 Answers1

0
exec 1>/tmp/logfile 2>&1
mycommand1
mycommand2
...
  • it is not working, i placed it just on the second line, and not output file is found after the bash job is finished. – jacky Mar 29 '17 at 14:22
  • Then maybe do this: logdir=$(mktemp -d);exec 1>"$logdir"/log 2>&1 –  Mar 29 '17 at 14:27