1

Im capturing all my script executions via the below command

exec > $LOGDIR/myfile.log
exec 2>&1

But the problem is my main script contains many other shell scripts(for different functions) which also captures another log in `$LOGDIR/myfile/today.log

If want to capture all the sub script executions also in one log file , say

$LOGDIR/myfile.log.

My present approach dosesn't capture exection details sub scripts.

Can you please help on this.

5
  • 1
    Are you sure you don't mean: exec >> $LOGDIR/myfile.log ? Commented Jun 18, 2015 at 12:32
  • yes, its is exec > $LOGDIR/myfile.log even if i append , the sub scripts are creating log in different directory. Bascially i want a single log file to capture everything that the main script and sub script executes Commented Jun 18, 2015 at 12:56
  • Create a script in which everything you want to log goes to the screen (stdout), then run the script and catch all the output and redirect it to a file. ./script.sh > stdout.error.log.txt 2>&1 Commented Jun 18, 2015 at 13:09
  • Nothing you do in a parent script will change the behavior of a child script writing to its own log file. You'll need to edit the other scripts to use a common log file.
    – Jeff Schaller
    Commented Jun 18, 2015 at 13:38
  • but this needs to be done inside the script and not outside while executing Commented Jun 19, 2015 at 7:09

2 Answers 2

2

If the child scripts are redirecting to file without at the same time printing their standard output/error streams you can't really do it in a flexible fashion. The canonical way to do this would be to ensure that scripts pipe their output to tee so that it can also be captured by the parent script.

0

The logs won't be in a terribly meaningful order, but you could always just concatenate each log file at the end of your script.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .