I use GNU Parallel along a for
loop like this:
for BAND in $(seq 1 "$BANDS") ;do
# Do not extract, unscale and merge if the scaled map exists already!
SCALED_MAP="era5_and_land_${VARIABLE}_${YEAR}_band_${BAND}_merged_scaled.nc"
MERGED_MAP="era5_and_land_${VARIABLE}_${YEAR}_band_${BAND}_merged.nc"
if [ ! -f "${SCALED_MAP+set}" ] ;then
echo "log $LOG_FILE Action=Merge, Output=$MERGED_MAP, Pixel size=$OUTPUT_PIXEL_SIZE_X $OUTPUT_PIXEL_SIZE_Y, Timestamp=$(timestamp)"
echo "gdalmerge_and_clean $VARIABLE $YEAR $BAND $OUTPUT_PIXEL_SIZE_X $OUTPUT_PIXEL_SIZE_Y"
else
echo "warning "Scaled map "$SCALED_MAP" exists already! Skipping merging.-""
fi
done |parallel -j 20 --joblog "parallel.${JOB_CLUSTER_PROCESS}.log"
log "$LOG_FILE" "Action=Merge, End=$(timestamp)"
(for the records: where ${JOB_CLUSTER_PROCESS}"
a variable given by HTCondor).
In the logs I see only entries of the first command
echo "log $LOG_FILE Action=Merge, Output=$MERGED_MAP, Pixel >size=$OUTPUT_PIXEL_SIZE_X $OUTPUT_PIXEL_SIZE_Y, Timestamp=$(timestamp)"
which is actually a custom way to log actions during this loop in the following way:
# tell what you are doing
function log {
echo "${@: 2}" 2>&1 >> "$1" ;
}
export -f log
Is it possible to get the second line
echo "gdalmerge_and_clean $VARIABLE $YEAR $BAND $OUTPUT_PIXEL_SIZE_X >$OUTPUT_PIXEL_SIZE_Y"
only or along with the first together included in the .log file created by --joblog
?
log
section (at the end of your script) does ) But if you want only this line:echo "gdalmerge_and_clean $VARIABLE $YEAR $BAND $OUTPUT_PIXEL_SIZE_X >$OUTPUT_PIXEL_SIZE_Y"
I think you can use:echo "log $LOG_FILE Action=Merge, Output=$MERGED_MAP, Pixel size=$OUTPUT_PIXEL_SIZE_X $OUTPUT_PIXEL_SIZE_Y, Timestamp=$(timestamp)"
>&2done
(the end of the for loop) redirect stderr to.null or some file:done > /dev/null
ordone > /path/to/somefile
log
is just a custom function that writes whatever is there in a custom.log
file. I am exploring the use of--joblog
and I realised that--joblog
records only the first line.while read -r line; do
afterdone
, like this:done | while read -r line; do parallel -j 20 --joblog "parallel.${JOB_CLUSTER_PROCESS}.log" ; done