9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] A simple rc question
@ 2007-05-15 15:38 ron minnich
  2007-05-15 15:46 ` Charles Forsyth
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: ron minnich @ 2007-05-15 15:38 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

This is a quick attempt at multitail, which does a tail -f on lots of
files, printing the lines from each with the name prepended.

This thing almost works -- except it blocks on each command, not & as
I expect. What did I do wrong?

#!/bin/rc
for(f)
	tail -f $f |  awk '{print "'^$f^':" $0}'&


ron


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A simple rc question
  2007-05-15 15:38 [9fans] A simple rc question ron minnich
@ 2007-05-15 15:46 ` Charles Forsyth
  2007-05-15 15:48 ` erik quanstrom
  2007-05-16  0:24 ` Kris Maglione
  2 siblings, 0 replies; 9+ messages in thread
From: Charles Forsyth @ 2007-05-15 15:46 UTC (permalink / raw)
  To: 9fans

cmd includes for's body:

cmdsa:	cmd ';'
|	cmd '&'			{$$=tree1('&', $1);}
	...
|	FOR '(' word IN words ')' {skipnl();} cmd


use

for(f)
	{tail -f $f |  awk '{print "'^$f^':" $0}'&}


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A simple rc question
  2007-05-15 15:38 [9fans] A simple rc question ron minnich
  2007-05-15 15:46 ` Charles Forsyth
@ 2007-05-15 15:48 ` erik quanstrom
  2007-05-15 16:08   ` ron minnich
  2007-05-16  0:24 ` Kris Maglione
  2 siblings, 1 reply; 9+ messages in thread
From: erik quanstrom @ 2007-05-15 15:48 UTC (permalink / raw)
  To: 9fans

i think you have backgrounded the awk, but not the tail.
i think what you want is

	for(f){
		{tail -f $f | awk '{print "'^$f^':" $0}'}&}
	}

it sure looks like there are excessive {}s, but i think they are necessary.
otherwise & will bind to either awk or the for.

- erik


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A simple rc question
  2007-05-15 15:48 ` erik quanstrom
@ 2007-05-15 16:08   ` ron minnich
  2007-05-15 16:18     ` Charles Forsyth
  0 siblings, 1 reply; 9+ messages in thread
From: ron minnich @ 2007-05-15 16:08 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 5/15/07, erik quanstrom <quanstro@coraid.com> wrote:
> i think you have backgrounded the awk, but not the tail.
> i think what you want is
>
>         for(f){
>                 {tail -f $f | awk '{print "'^$f^':" $0}'}&}
>         }
>
> it sure looks like there are excessive {}s, but i think they are necessary.
> otherwise & will bind to either awk or the for.

I suspected that and will try it, but the man page is pretty clear (I
thought) that
a|b is a single command. I still think the & should bind to the
pipeline, but ...

ron


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A simple rc question
  2007-05-15 16:08   ` ron minnich
@ 2007-05-15 16:18     ` Charles Forsyth
  0 siblings, 0 replies; 9+ messages in thread
From: Charles Forsyth @ 2007-05-15 16:18 UTC (permalink / raw)
  To: 9fans

> I suspected that and will try it, but the man page is pretty clear (I
> thought) that
> a|b is a single command. I still think the & should bind to the
> pipeline, but ...

a PIPE is a cmd, so i'd expect that too.
it would also be tedious if
	cat burp | sed 's/mumble/frog/' | md5sum &
ran only the md5sum in the background.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A simple rc question
  2007-05-15 15:38 [9fans] A simple rc question ron minnich
  2007-05-15 15:46 ` Charles Forsyth
  2007-05-15 15:48 ` erik quanstrom
@ 2007-05-16  0:24 ` Kris Maglione
  2 siblings, 0 replies; 9+ messages in thread
From: Kris Maglione @ 2007-05-16  0:24 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 277 bytes --]

Incidentally, might I suggest something to the effect of:

#!/bin/rc

fn cleanup { for(i in $apids) { echo kill >/proc/$i/note } }
fn sigint { cleanup }
fn sigterm { cleanup }

apids=()
for(f) {
  	tail -f $f | sed 's/^/'$f:/ &
	apids = ($apids $apid)
}

wait


[-- Attachment #2: Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A simple rc question
  2007-05-15 23:29 ` ron minnich
@ 2007-05-15 23:35   ` Kris Maglione
  0 siblings, 0 replies; 9+ messages in thread
From: Kris Maglione @ 2007-05-15 23:35 UTC (permalink / raw)
  To: 9fans

[-- Attachment #1: Type: text/plain, Size: 491 bytes --]

On Tue, May 15, 2007 at 04:29:45PM -0700, ron minnich wrote:
> That works fine. But in a for it did not. This did work however:
> for(i){{tail -f $i | whatever}&}

The second set of braces is superfluous. The & binds looser than the |, 
and also looser than the for loop. Simply for(i) { tail -f $i | foo & } 
is sufficient.

-- 
Kris Maglione

Real programmers don't eat quiche.  In fact, real
programmers don't know how to spell quiche.  They eat
twinkies and szechuan food.

[-- Attachment #2: Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [9fans] A simple rc question
  2007-05-15 23:03 Benn Newman
@ 2007-05-15 23:29 ` ron minnich
  2007-05-15 23:35   ` Kris Maglione
  0 siblings, 1 reply; 9+ messages in thread
From: ron minnich @ 2007-05-15 23:29 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

On 5/15/07, Benn Newman <benn.newman@snc.edu> wrote:
> Duff answered ron's question in "Rc — The Plan 9 Shell".
>
>    12. Command grouping
>
>    A sequence of commands enclosed in {} may be used anywhere a command is
>    required. For example:
>
>       {sleep 3600;echo 'Time''s up!'}&
>
>    will wait an hour in the background, then print a message. Without the
>    braces,
>
>       sleep 3600;echo 'Time''s up!'&
>
>    would lock up the terminal for an hour, then print the message in the
>    background.


it does not really answer the question.
cmd ; cmd is two commands.
cmd | cmd is one command.
cmd ; cmd & will background the second command
cmd|cmd & should background both.

Just try this:
sleep 5|wc

and then
sleep 5|wc&

The | forms the two commands into a compound and the compound is backgrounded.

That works fine. But in a for it did not. This did work however:
for(i){{tail -f $i | whatever}&}

ron


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: [9fans] A simple rc question
@ 2007-05-15 23:03 Benn Newman
  2007-05-15 23:29 ` ron minnich
  0 siblings, 1 reply; 9+ messages in thread
From: Benn Newman @ 2007-05-15 23:03 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Duff answered ron's question in “Rc — The Plan 9 Shell”.

   12. Command grouping

   A sequence of commands enclosed in {} may be used anywhere a command is
   required. For example:

      {sleep 3600;echo ’Time’’s up!’}&

   will wait an hour in the background, then print a message. Without the
   braces,

      sleep 3600;echo ’Time’’s up!’&

   would lock up the terminal for an hour, then print the message in the
   background.

>===== Original Message From Fans of the OS Plan 9 from Bell Labs 
<9fans@cse.psu.edu> =====
>> I suspected that and will try it, but the man page is pretty clear (I
>> thought) that
>> a|b is a single command. I still think the & should bind to the
>> pipeline, but ...
>
>a PIPE is a cmd, so i'd expect that too.
>it would also be tedious if
>	cat burp | sed 's/mumble/frog/' | md5sum &
>ran only the md5sum in the background.

--
Benn Newman



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2007-05-16  0:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-15 15:38 [9fans] A simple rc question ron minnich
2007-05-15 15:46 ` Charles Forsyth
2007-05-15 15:48 ` erik quanstrom
2007-05-15 16:08   ` ron minnich
2007-05-15 16:18     ` Charles Forsyth
2007-05-16  0:24 ` Kris Maglione
2007-05-15 23:03 Benn Newman
2007-05-15 23:29 ` ron minnich
2007-05-15 23:35   ` Kris Maglione

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).