vmstat | sed WORKS vmstat | logger WORKS vmstat | sed | logger FAILS - NEED HELP

vmstat | sed WORKS vmstat | logger WORKS vmstat | sed | logger FAILS - NEED HELP

Post by jabe_on » Sun, 16 Apr 2000 04:00:00



I am using FreeBSD 3.3.

The following two pipes work fine:

vmstat -w 5 | logger -p local0.info
vmstat -w 5 | sed -e /procs/d -e /fre/d

But don't work when combined into:

vmstat -w 5 | sed -e /procs/d -e /fre/d | logger -p local0.info

I don't understand why.  Any suggestions?

 
 
 

vmstat | sed WORKS vmstat | logger WORKS vmstat | sed | logger FAILS - NEED HELP

Post by Jefferson Ogat » Sun, 16 Apr 2000 04:00:00



> I am using FreeBSD 3.3.

> The following two pipes work fine:

> vmstat -w 5 | logger -p local0.info
> vmstat -w 5 | sed -e /procs/d -e /fre/d

> But don't work when combined into:

> vmstat -w 5 | sed -e /procs/d -e /fre/d | logger -p local0.info

> I don't understand why.  Any suggestions?

Output buffering by sed?

--
Jefferson Ogata : Internetworker, Antibozo



 
 
 

vmstat | sed WORKS vmstat | logger WORKS vmstat | sed | logger FAILS - NEED HELP

Post by jabe_on » Sun, 16 Apr 2000 04:00:00


I checked out the man page for sed.  It indicates to me that the pipe should
work, based on the statement:

"The sed utility reads the specified files, or the standard input if no
files are specified, modifying the input as specified by a list of commands.
The input is then written to the standard output."

So, my understanding is that sed should take standard in form vmstat,
process it, and output standard out.  Your statements indicate that I am
wrong.  This newbie would appreciate an explanation.



> > I am using FreeBSD 3.3.

> > The following two pipes work fine:

> > vmstat -w 5 | logger -p local0.info
> > vmstat -w 5 | sed -e /procs/d -e /fre/d

> > But don't work when combined into:

> > vmstat -w 5 | sed -e /procs/d -e /fre/d | logger -p local0.info

> > I don't understand why.  Any suggestions?

> Output buffering by sed?

> --
> Jefferson Ogata : Internetworker, Antibozo

ICQ: 19569681



 
 
 

vmstat | sed WORKS vmstat | logger WORKS vmstat | sed | logger FAILS - NEED HELP

Post by Jefferson Ogat » Sun, 16 Apr 2000 04:00:00



> I checked out the man page for sed.  It indicates to me that the pipe should
> work, based on the statement:

> "The sed utility reads the specified files, or the standard input if no
> files are specified, modifying the input as specified by a list of commands.
> The input is then written to the standard output."

> So, my understanding is that sed should take standard in form vmstat,
> process it, and output standard out.  Your statements indicate that I am
> wrong.  This newbie would appreciate an explanation.

I'm not saying you're wrong. You're perfectly correct.

My theory is that sed is saving up its output until it fills its output buffer,
probably 4K or 8K bytes, then flushing it all to the pipe in one write. This is
typical behavior for a lot of Unix commands. vmstat by itself is designed to
write one line at a time to standard output and flush its output after each
line, so in the direct vmstat | logger example, logger gets the lines from
vmstat as they are written. When piped through sed, however, the output is
being saved up by sed until it hits that buffer size and then being sent to
logger in one big chunk. You're not seeing anything logged because you're not
waiting long enough for the buffer to be filled.

Many Unix stream processing programs observe whether their output file is a
terminal device and do line buffering if so, and otherwise do block buffering
for efficiency. Read the man page for setbuf or setbuffer for an explanation of
this. To work around this, you'll probably have to come up with some way to
invoke sed only once for each line of input, perhaps piping vmstat into xargs
and invoking an echo | sed | logger pipeline.




> > > I am using FreeBSD 3.3.

> > > The following two pipes work fine:

> > > vmstat -w 5 | logger -p local0.info
> > > vmstat -w 5 | sed -e /procs/d -e /fre/d

> > > But don't work when combined into:

> > > vmstat -w 5 | sed -e /procs/d -e /fre/d | logger -p local0.info

> > > I don't understand why.  Any suggestions?

> > Output buffering by sed?

--
Jefferson Ogata : Internetworker, Antibozo


 
 
 

vmstat | sed WORKS vmstat | logger WORKS vmstat | sed | logger FAILS - NEED HELP

Post by Alexander Bochman » Sun, 16 Apr 2000 04:00:00



 > But don't work when combined into:
 > vmstat -w 5 | sed -e /procs/d -e /fre/d | logger -p local0.info
 > I don't understand why.  Any suggestions?

Problems with line buffering or something?

Anyway, the following seems to work fine, logger is executed for
every line of output:

vmstat -w 5 | awk '/^\ [0-9]/ {print | "logger -p local0.info" }'

Alex.

 
 
 

vmstat | sed WORKS vmstat | logger WORKS vmstat | sed | logger FAILS - NEED HELP

Post by jabe_on » Sun, 16 Apr 2000 04:00:00


That seems to be working like a charm.    Seems I just need to remember to
think forwards and backwards..


>  > But don't work when combined into:
>  > vmstat -w 5 | sed -e /procs/d -e /fre/d | logger -p local0.info
>  > I don't understand why.  Any suggestions?

> Problems with line buffering or something?

> Anyway, the following seems to work fine, logger is executed for
> every line of output:

> vmstat -w 5 | awk '/^\ [0-9]/ {print | "logger -p local0.info" }'

> Alex.

 
 
 

1. vmstat | sed WORKS vmstat | logger WORKS vmstat | sed | logger FAILS

I am using FreeBSD 3.3.  The following two pipes work fine:

vmstat -w 5 | logger -p local0.info
vmstat -w 5 | sed -e /procs/d -e /fre/d

But don't work when combined into:

vmstat -w 5 | sed -e /procs/d -e /fre/d | logger -p local0.info

I don't understand why.  Any suggestions?

2. g++ / iostream problem

3. vmstat doesn't work when y2k fix applied on 4.3.1

4. redhat 6.1 dual boot

5. vmstat can't work in 4.3.3

6. Syquest EZ135 Drive

7. Q)vmstat doesn't work.

8. I Need A Shell Script, Or A C Program....

9. How does vmstat work?

10. vmstat: 0551-129 knlist failed

11. vmstat fail

12. vmstat failed

13. need help with system logger FAILED on boot