This question already has an answer here:

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:

exec 2>&1
} 2>&1 | tee -a /tempfolder

marked as duplicate by don_crissti, xhienne, Toby Speight, Tim Kennedy, Archemar Mar 29 '17 at 14:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

exec 1>/tmp/logfile 2>&1
  • 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 – user218374 Mar 29 '17 at 14:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.