linux - Restrict logging for a particular child shell script -
i'm running bunch of scripts through 1 main parent script. have added logging code in parent script below:
exec 3>&1 4>&2 trap 'exec 2>&4 1>&3' 0 1 2 3 exec 1>logfilename 2>&1
this generates logs child scripts. want skip log generation 1 particular script, since logs can heavy @ times.
is there way this? many thanks!
my parent script looks this:
mkdir -p $scriptfolder/log logfile="$scriptfolder/log/$(echo "$4" | tr -d '\n\r')_log_importmain_$datetime.log" exec 3>&1 4>&2 trap 'exec 2>&4 1>&3' 0 1 2 3 exec 1>$logfile 2>&1 source $scriptfolder/shellscripts/1.copyfilesfromftp.sh source $scriptfolder/shellscripts/2.import.sh source $scriptfolder/shellscripts/3.export.sh source $scriptfolder/shellscripts/4.copyfilestoftp.sh
i want skip logging 3.export.sh, there way possible this?
you not running scripts subprocesses, question implies "parent" term, anyway, can have redirection individual command, this:
mkdir -p "$scriptfolder"log # notice quoting logfile="$scriptfolder/log/$(echo "$4" | tr -d '\n\r')_log_importmain_$datetime.log" exec 3>&1 4>&2 trap 'exec 2>&4 1>&3' 0 1 2 3 15 # notice addition of 15 exec 1>"$logfile" 2>&1 # notice quoting here, source $scriptfolder/shellscripts/1.copyfilesfromftp.sh source $scriptfolder/shellscripts/2.import.sh # temporarily disable logging source statement source $scriptfolder/shellscripts/3.export.sh >/dev/null 2>&1 source $scriptfolder/shellscripts/4.copyfilestoftp.sh
the >/dev/null 2>&1
in effect duration of third source
statement, , file descriptors restored previous state when finishes.
by way, sure "$4"
can contain embedded newlines, , want remove them in case? trailing newline echo
trimmed off anyway, perhaps want logfile="$scriptfolder/log/${4}_log_importmain_$datetime.log"
Comments
Post a Comment