parallel bash scripts

Rick Stevens rstevens at corp.alldigital.com
Wed Mar 28 00:56:31 UTC 2012


On 03/27/2012 04:06 PM, bruce wrote:
> dave..
>
> thanks.
>
> but the script is a long running script, and i want to see the output
> as the script is running without having to hit the keyboard..
>
> so doing a tail of the file while the process is running isn't what
> i'm looking for.
>
> anything else?

The problem is that a script wants a stdin, stdout and stderr. If
you're going to run them in parallel, you can't very well have both
scripts outputting to the terminal.

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. 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 then "screen -r <id>" to attach to those screen sessions. You
can get the list of screen sessions running simply by doing "screen -r"
without specifying a session ID. Use "ctrl-A, ctrl-D" to detach from
a screen session (but leave it running). See "man screen" for details.

Oh, yeah, you may need to "yum install screen" if you don't already have
it.

> On Tue, Mar 27, 2012 at 7:00 PM, Dave Ihnat<dihnat at dminet.com>  wrote:
>> On Tue, Mar 27, 2012 at 06:06:56PM -0400, bruce wrote:
>>> anyway i can redirect the err/out to the stdout.. instead of the
>>> nohut.out file??
>>
>> The usual way would be to do a tail -f on the output file, e.g.,
>>
>> Â nohup cat.sh 2>&1>cat.log
>> Â tail -f cat.log
>>
>> If you're using bash, IIRC, you could reap the background ID and then use
>> 'disown', I suppose. Â "$!" should give you that.
>>
>> Cheers,
>> --
>> Â  Â  Â  Â Dave Ihnat
>> Â  Â  Â  Â President, DMINET Consulting, Inc.
>> --
>> users mailing list
>> users at lists.fedoraproject.org
>> To unsubscribe or change subscription options:
>> https://admin.fedoraproject.org/mailman/listinfo/users
>> Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
>> Have a question? Ask away: http://ask.fedoraproject.org


-- 
----------------------------------------------------------------------
- Rick Stevens, Systems Engineer, AllDigital    ricks at alldigital.com -
- AIM/Skype: therps2        ICQ: 22643734            Yahoo: origrps2 -
-                                                                    -
-      We are born naked, wet and hungry. Then things get worse.     -
----------------------------------------------------------------------


More information about the users mailing list