[9fans] A simple rc question - Plan9

This is a discussion on [9fans] A simple rc question - Plan9 ; 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 ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: [9fans] A simple rc question

  1. [9fans] A simple rc question

    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

  2. Re: [9fans] A simple rc question

    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

  3. Re: [9fans] A simple rc question

    On 5/15/07, erik quanstrom 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

  4. Re: [9fans] A simple rc question

    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}'&}

  5. Re: [9fans] A simple rc question

    > 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.


  6. Re: [9fans] A simple rc question

    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


    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v2.0.3 (FreeBSD)

    iD8DBQFGSk8qseQZD8Aui4wRArxMAJ0TAYAjdcCa7AHneyRQRX N0RRr4WgCfXQqL
    wAgh/pzOBa8gS5ALM3c8Hgg=
    =2nsO
    -----END PGP SIGNATURE-----


+ Reply to Thread