parallel bash scripts
Cameron Simpson
cs at zip.com.au
Wed Mar 28 05:28:05 UTC 2012
On 27Mar2012 17:56, Rick Stevens <rstevens at corp.alldigital.com> wrote:
| On 03/27/2012 04:06 PM, bruce wrote:
| The problem is that a script wants a stdin, stdout and stderr.
No evidence so far that they use stdin.
| If
| you're going to run them in parallel, you can't very well have both
| scripts outputting to the terminal.
Sure you can. Why not? I do it all the time with multiple tails etc.
| The correct thing is to do what Dave said. Use nohup and redirect stdout
| and stderr to a log file. You can then "tail -f" each one whenever you
| want.
Background and disown is better, usually. I'm finding nohup more and
more painful; always the same output file, stdout and stderr glommed
together etc.
| An alternative is to launch the scripts in detached screen
| sessions:
|
| screen -d -m dog.sh
| screen -d -m cat.sh
|
| This would launch each script in its own detached screen session
| (essentially creates virtual terminals with shells and runs the script
| in them) and the calling script doesn't wait for them to complete.
You can get screen session names, too. Much easier to work with than the
ids you get by default.
% screen -ls
There are screens on:
2635.GETMAIL (Detached)
17863.CP_VIDEO (Detached)
6557.OI (Detached)
1247.BACKUP (Detached)
2203.BEYONWIZ (Detached)
9125.EMERGE (Detached)
15806.mutt-28mar2012-16:23 Re_parallel_bash_scr (Attached)
7 Sockets in /tmp/screen-cameron.
That last is actually the email editor I'm using right now. Can detach
and pick up again later!
But:
dog.sh </dev/null >dog.out 2>dog.err &
cat.sh </dev/null >cat.out 2>cat.err &
disown %1 %2
is simple and basic. Adjust %1 and %2 to the job numbers you get; see the
"jobs" command to get current background jobs.
Cheers,
--
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
To understand recursion, you must first understand recursion.
More information about the users
mailing list