FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Fedora User

 
 
LinkBack Thread Tools
 
Old 03-27-2012, 09:25 PM
bruce
 
Default parallel bash scripts

hi.

got a couple of test bash scripts.

dog.sh, cat.sh
each script runs the underlying php in an endless loop.

I'm trying to figure out how to run the scripts in parallel, from the
same parent shell script. something like:

test.sh

dog.sh > &2
cat.sh > &2

where dog.sh would be :
--------------------------------
while true
do
pgrep dog
if [ $? -ne 0 ]
then
/dog.php
fi
sleep 5
done

my current tests, run dog.sh, which runs the dog.php ... but the test
never gets to run cat.sh

thoughts/comments...

thanks
--
users mailing list
users@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
 
Old 03-27-2012, 09:46 PM
Mateusz Marzantowicz
 
Default parallel bash scripts

W dniu 27.03.2012 23:25, bruce pisze:
> hi.
>
> got a couple of test bash scripts.
>
> dog.sh, cat.sh
> each script runs the underlying php in an endless loop.
>
> I'm trying to figure out how to run the scripts in parallel, from the
> same parent shell script. something like:
>
> test.sh
>
> dog.sh > &2
> cat.sh > &2
>
> where dog.sh would be :
> --------------------------------
> while true
> do
> pgrep dog
> if [ $? -ne 0 ]
> then
> /dog.php
> fi
> sleep 5
> done
>
> my current tests, run dog.sh, which runs the dog.php ... but the test
> never gets to run cat.sh
>
> thoughts/comments...
>
> thanks
Did you try:

command1 & command2

where command1 and command2 are bash built in commands or scripts (in
your case dog.sh and cat.sh)?


Mateusz Marzantowicz
--
users mailing list
users@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
 
Old 03-27-2012, 09:53 PM
bruce
 
Default parallel bash scripts

HI Mateusz

Yeah, tried the basic "&" ... but the issue is the shell scripts run
as infinite loops.. and therefore, the dog.sh doesn't really
exit/complete.

So I can't really run them sequentially.

If I open up separate term/windows, then of course, I can manually run
them (one in each window)..

thanks


On Tue, Mar 27, 2012 at 5:46 PM, Mateusz Marzantowicz
<mmarzantowicz@osdf.com.pl> wrote:
> W dniu 27.03.2012 23:25, bruce pisze:
>> hi.
>>
>> got a couple of test bash scripts.
>>
>> dog.sh, cat.sh
>> each script runs the underlying php in an endless loop.
>>
>> I'm trying to figure out how to run the scripts in parallel, from the
>> same parent shell script. something like:
>>
>> test.sh
>>
>> * dog.sh > &2
>> * cat.sh > &2
>>
>> where dog.sh would be :
>> --------------------------------
>> while true
>> do
>> * pgrep dog
>> * if [ $? -ne 0 ]
>> * then
>> * * /dog.php
>> * fi
>> sleep 5
>> done
>>
>> my current tests, run dog.sh, which runs the dog.php ... but the test
>> never gets to run cat.sh
>>
>> thoughts/comments...
>>
>> thanks
> Did you try:
>
> command1 & command2
>
> where command1 and command2 are bash built in commands or scripts (in
> your case dog.sh and cat.sh)?
>
>
> Mateusz Marzantowicz
> --
> users mailing list
> users@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
--
users mailing list
users@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
 
Old 03-27-2012, 09:58 PM
Dave Ihnat
 
Default parallel bash scripts

On Tue, Mar 27, 2012 at 05:25:56PM -0400, bruce wrote:
> got a couple of test bash scripts.
> ...
> I'm trying to figure out how to run the scripts in parallel, from the
> same parent shell script. something like:

Have you tried

nohup cat.sh 2>&1&
nohup dog.sh 2>&1&

Cheers,
--
Dave Ihnat
--
users mailing list
users@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
 
Old 03-27-2012, 10:06 PM
bruce
 
Default parallel bash scripts

hey dave...

anyway i can redirect the err/out to the stdout.. instead of the
nohut.out file??

it appears that the processes are running in the ps tb.. the nohut.out
file also has input/data..

i'd like to be able to see the output of the processes scroll on the
term/screen if possible

thanks


On Tue, Mar 27, 2012 at 5:58 PM, Dave Ihnat <dihnat@dminet.com> wrote:
> On Tue, Mar 27, 2012 at 05:25:56PM -0400, bruce wrote:
>> got a couple of test bash scripts.
>> ...
>> I'm trying to figure out how to run the scripts in parallel, from the
>> same parent shell script. something like:
>
> Have you tried
>
> *nohup cat.sh 2>&1&
> *nohup dog.sh 2>&1&
>
> Cheers,
> --
> * * * *Dave Ihnat
> --
> users mailing list
> users@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
--
users mailing list
users@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
 
Old 03-27-2012, 11:00 PM
Dave Ihnat
 
Default parallel bash scripts

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@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
 
Old 03-27-2012, 11:06 PM
bruce
 
Default parallel bash scripts

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?

thanks


On Tue, Mar 27, 2012 at 7:00 PM, Dave Ihnat <dihnat@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@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
--
users mailing list
users@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
 
Old 03-28-2012, 12:56 AM
Rick Stevens
 
Default parallel bash scripts

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@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@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@alldigital.com -
- AIM/Skype: therps2 ICQ: 22643734 Yahoo: origrps2 -
- -
- We are born naked, wet and hungry. Then things get worse. -
----------------------------------------------------------------------
--
users mailing list
users@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
 
Old 03-28-2012, 12:57 AM
suvayu ali
 
Default parallel bash scripts

On Wed, Mar 28, 2012 at 01:06, bruce <badouglas@gmail.com> wrote:
> 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..

I'm not sure what you mean. Do you mean to say you want to run the
script and start seeing the output with the same command? If that is
the case, there are several solutions. I usually use these two:

$ nohup myscript &> myscript.log & less +F myscript.log
$ nohup myscript 2>&1 | tee myscript.log

If you actually want to run both scripts in the same shell and want to
follow both outputs, try the following variation of the first command:

$ nohup myscript1 &> myscript1.log & nohup myscript2 &> myscript2.log
& less +F myscript1.log myscript2.log

Then you can stop following the first log by hitting Ctrl+c and move
on to the next file with :n you can then start following with F. You
can go back again by repeating the same except change :n to .

Hope this helps.

--
Suvayu

Open source is the future. It sets us free.
--
users mailing list
users@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
 
Old 03-28-2012, 01:00 AM
Mark LaPierre
 
Default parallel bash scripts

On 03/27/2012 05:25 PM, bruce wrote:

hi.

got a couple of test bash scripts.

dog.sh, cat.sh
each script runs the underlying php in an endless loop.

I'm trying to figure out how to run the scripts in parallel, from the
same parent shell script. something like:

test.sh


where dog.sh would be :
--------------------------------
while true
do
pgrep dog
if [ $? -ne 0 ]
then
/dog.php
fi
sleep 5
done

my current tests, run dog.sh, which runs the dog.php ... but the test
never gets to run cat.sh

thoughts/comments...

thanks

Hey Bruce,

Do you mean to run these subprograms in parallel or in series?

cat.sh
#! /bin/bash

CAT=0
until [ $CAT -eq 10 ]
do
echo "Inside a dog it's too dark to read. $CAT"
CAT=$[$CAT + 1]
sleep 2
done


dog.sh
#! /bin/bash

DOG=0
until [ $DOG -eq 10 ]
do
echo "Next to a dog a book is man's best friend. $DOG"
DOG=$[$DOG + 1]
sleep 2
done


test.sh
#! /bin/sh

/home/mlapier/test/dog.sh 1>&2 &
/home/mlapier/test/cat.sh 1>&2 &


[mlapier@mushroom test]$ ./test.sh
[mlapier@mushroom test]$ Next to a dog a book is man's best friend. 0
Inside a dog it's too dark to read. 0
Next to a dog a book is man's best friend. 1
Inside a dog it's too dark to read. 1
Next to a dog a book is man's best friend. 2
Inside a dog it's too dark to read. 2
Next to a dog a book is man's best friend. 3
Inside a dog it's too dark to read. 3
Next to a dog a book is man's best friend. 4
Inside a dog it's too dark to read. 4
Next to a dog a book is man's best friend. 5
Inside a dog it's too dark to read. 5
Next to a dog a book is man's best friend. 6
Inside a dog it's too dark to read. 6
Next to a dog a book is man's best friend. 7
Inside a dog it's too dark to read. 7
Next to a dog a book is man's best friend. 8
Inside a dog it's too dark to read. 8
Next to a dog a book is man's best friend. 9
Inside a dog it's too dark to read. 9


--
users mailing list
users@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
 

Thread Tools




All times are GMT. The time now is 01:07 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org