Running centos 2.6, I have a bash script in which I'd like to run a number of background threads in parallel, tee'ing the results of the entire script to one file, while tee'ing the result of each background thread to another.
Here's what I'm doing, where the number of csv files control the number of background threads.
cat test.sh
#!/bin/bash
OUTPUT_DIR=/tmp
ant upgrade.system
EXEC_DATE=`date +%Y:%m:%d:%M`
for file in `ls -d $OUTPUT_DIR/Info*.csv` ; do
ant upgrade.file -Dfile $file | tee -a $file.$EXEC_DATE.log &
done
and I'd like to run this as
bash test.sh | tee test.out
In my simple test this works, with all output going to test.out and background thread specific output going to $file.$EXEC_DATE.log.
Is this ok, or is tee'ing output in background threads dangerous for any reason?
Other people using this script have complained that output to test.out stops in some error conditions, even though background threads continue running.
Thanks, Jim