On Mon, Jul 17, 2006 at 06:36:55AM -0400, Gary R. Leaf wrote: > >hi > > > >I find that in many cases I need my background tasks to be executed in > >sequence. Ie, I need background task-b to start right after background > >task-a has properly started. > > > >So far I haven't found a good way to do it. I used > > > >task-a & sleep 2; task-b & > > > >but that 'sleep 2' has changed to 'sleep 5' and still sometimes task-b > >starts before task-a. I can raise the wait time, but it means that task-b > >would normally start too late... > > > >Any good way? > > > >thanks > > > > > > > Set up a script that checks the return codes. > > if return code of task A is 0 then > task B > else > do something else > > if rturn code of task B is 0 then > task C > else > do something else > > and so on > > execute the controlling script in the background
You don't need a script - just use the 'conditional and' operator of the shell: (cmd1 && cmd2 && cmd3)& will execute cmd1 to cmd3 in sequence, aborting if any fail. If you don't want to abort on error, use ';' to separate the commands... from the 'sh' manpage: ``&&'' and ``||'' are AND-OR list operators. ``&&'' exe- cutes the first command, and then executes the second com- mand iff the exit status of the first command is zero. ``||'' is similar, but executes the second command iff the exit status of the first command is nonzero. ``&&'' and ``||'' both have the same priority. DigbyT -- Digby R. S. Tarvin digbyt(at)digbyt.com http://www.digbyt.com -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]