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.
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
Last edited by Scott; 08-25-2010 at 01:14 PM..
Reason: Please use code tags
Running centos 2.6, I have a bash script in which I'd like to run a number of background threads in parallel
I think you mean processes. Threads are something entirely different, and something BASH can't manage.
Quote:
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
"for file in `ls *`" is a useless use of backticks. You could just do "for file in $OUTPUT_DIR/Info*.csv" for the same effect without using ls or backticks at all.
On further checking, I see you are writing a different file for every process. This is safe. So is putting it behind another tee. Why is it dying? Make sure you're not exceeding the users' limit for the maximum number of processes they're allowed.
Last edited by Corona688; 08-25-2010 at 01:22 PM..
I'm on Ubuntu 14.04 and I manually updated my coreutils so that "tee" is now on version 8.27
I was running a script using bash where there is some write to pipe error at some point causing the tee command to exit abruptly while the script continues to run. The newer version of tee seems to prevent... (2 Replies)
Hello! I have got a homework. The bash script runs in the background and checks the user's mailbox and when the user gets a new mail a popup window appears with some text and information about the sender (from who and when).I have no idea how to start, any help would be appreciated! Thank you:) (1 Reply)
Heyas,
Since this question (similar) occur every now and then, and given the fact i was thinking about it just recently (1-2 weeks) anyway, i started to write something :p
The last point for motivation was... (17 Replies)
I'm having trouble with part of this bash script in Linux where I respawn a new instance of script and kill the old one to prevent forking (Yes, I know 'exec' will not fork but this needs to be interactive) When the old instance is kill it pops up "Terminated!" in the middle of the new instance... (7 Replies)
NOTE: I am using BASH and Solaris 10 for this.
Currently in the process of building a script that has a main "watcher" daemon that reads a configuration file and starts background processes based on it's global configuration. It is basically an infinite loop of configuration reading. Some of the... (4 Replies)
I am trying to use a loop to start tasks 0-3, running 0,1,2 in the background with &.
FOLDSET=( 0 1 2 3 )
for FOLDSET in ${FOLDSET}
do
if ; then
BACKGRD="&"
else
BACKGRD=""
fi
# start task $FOLDSET
task1 -nogui -ni -p $PROJ \
epochs=$EPOS ... (3 Replies)
I have script 3 scripts 1 parent (p1) and 2 children child1 and child2
I have script 3 scripts
1 parent
2 children
child1
child2
In the code below the 2 child processes fire almost Instantaneously in
the background, Is that possible to know the status of pass/fail of each
process... (12 Replies)
I have script 3 scripts
1 parent
2 children
child1
child2
In the code below the 2 child processes fire almost Instantaneously in the background, Is that possible to know the status of pass/fail of each process "as it happens" ?
In the present scenario although Child2... (5 Replies)
Hi all,
How can I get the list of all Threads and the Total count of threads under a particular process ?
Do suggest !!
Awaiting for the replies !!
Thanks
Varun:b: (2 Replies)
nohup /bin/bassh $HOME/scripts/test.sh > $HOME/log/test.log 2>&1 &
nohup $HOME/scripts/test.sh > $HOME/log/test.log 2>&1 &
Which is the good practice to run a script in background of above two ?
does the first one will have any overhead on the system ?
our system is SunOS 5.10... (2 Replies)