supervision - discussion about system services, daemon supervision, init, runlevel management, and tools such as s6 and runit
 help / color / mirror / Atom feed
* OT: svlogd-logprocessor with bash/multitee
@ 2005-04-13 13:58 Henrik Heil
  2005-04-13 16:50 ` Paul Jarc
  0 siblings, 1 reply; 2+ messages in thread
From: Henrik Heil @ 2005-04-13 13:58 UTC (permalink / raw)


Hello list,

this is OT but i encountered this problem when i tried to write a 
socklog svlogd-processor that does the following:

- copy stdin to stdout (unaltered)
- pipe stdin through a programm that mails a report
- pipe stdin through a second programm that writes some html statistics

I'm not too familiar with doing descriptor-manipulation in shell-scripts 
but i think it cannot be done with pure sh (or bash in this case) so i 
tried to do this with bash & djbs multitee.

To keep my test simple i use sed to emulate the report-programms.
The closest i got was to make it work with one programm:

--- 8< ---

# cat logproc.sh

#!/bin/sh
exec 6>&1
/usr/bin/multitee 0:6 0:7 \
7>&1 | sed s/test_stdin/test_fd7/

# echo test_stdin | ./logproc.sh

test_stdin
test_fd7

--- >8 ---


Now with 2 programms:

--- 8< ---

# cat logproc.sh

#!/bin/sh
exec 6>&1
/usr/bin/multitee 0:6 0:7 0:8 \
7>&1 | sed s/test_stdin/test_fd7/ \
8>&1 | sed s/test_stdin/test_fd8/

# echo test_stdin | ./logproc.sh

test_stdin
[...programm does not return]

--- >8 ---

I assume it's just my lacking shell-programming skills ;-).
Allthough I wasn't lucky googling for an answer i think it's no too 
uncommon to want something like this in a logprocessor.

Maybe someone has done that before.
Any help is appreciated.

Thanks,
Henrik

-- 
Henrik Heil, zweipol Coy & Heil GbR
http://www.zweipol.net/


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

* Re: OT: svlogd-logprocessor with bash/multitee
  2005-04-13 13:58 OT: svlogd-logprocessor with bash/multitee Henrik Heil
@ 2005-04-13 16:50 ` Paul Jarc
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Jarc @ 2005-04-13 16:50 UTC (permalink / raw)
  Cc: supervision

Henrik Heil <hhml@zweipol.net> wrote:
> /usr/bin/multitee 0:6 0:7 \
> 7>&1 | sed s/test_stdin/test_fd7/

This can be simplified a bit:
multitee 0:6 0:1 | sed s/test_stdin/test_pipe/

> #!/bin/sh
> exec 6>&1
> /usr/bin/multitee 0:6 0:7 0:8 \
> 7>&1 | sed s/test_stdin/test_fd7/ \
> 8>&1 | sed s/test_stdin/test_fd8/
>
> # echo test_stdin | ./logproc.sh
>
> test_stdin
> [...programm does not return]

You have the second pipe set up between the two seds, but you want it
to be between multitee and the second sed:

{ { exec 7>&1 &&
    multitee 0:6 0:7 0:1 | sed s/test_stdin/test_pipe1/ >&6
  } | sed s/test_stdin/test_pipe2/
} 6>&1

bash has an extension that makes this easier:

multitee 0:1 \
  0:6 6> >(sed s/test_stdin/test_pipe1/) \
  0:7 7> >(sed s/test_stdin/test_pipe2/)


paul


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

end of thread, other threads:[~2005-04-13 16:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-13 13:58 OT: svlogd-logprocessor with bash/multitee Henrik Heil
2005-04-13 16:50 ` Paul Jarc

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