redirected output is buffered, how do you flush it?

Robert L. Howard rhoward at msd.gatech.edu
Tue Feb 5 09:29:24 AEST 1991


I have a script that after several pipe stops outputs a line
of information.  When run from a tty it outputs a line every
few seconds to several minutes.  Wrapped around the commands
is an infinite loop.  I can specify a trap command that will
close up things gracefully (print summary info etc.).

The problem comes in when I run:

% script > some_file

and then kill it some number of minutes later.  The total output
of the script is still in some buffer somewhere and doesn't make
it to the file.  Is there some command I can put in the 'trap' to
force it to flush the buffers?  Or is there a recommended way to
kill the job (other than ^C) that will force the buffers to flush?

Here is the script if you are wondering what I am talking about...

------------------------------------------------------------------
#! /bin/sh
#
pstat=/usr/etc/pstat


trap <Some-command_here> 1 2 3 14 15

echo "Starting at `date`"
echo "Interval is $1 seconds."
echo ""

while true
do
    $pstat -T | sed -e 's/\//\ /g'
    sleep $1
done | awk '
/files/	{ if ($1 > files) {
	files = $1
	printf ("max files\t%5d out of %5d, or %6.2f%\n", \
		files, $2, 100*files/$2) }
    }' -
----------------------------------------------------------------

Thanks

Robert
--
| Robert L. Howard             |    Georgia Tech Research Institute     |
| rhoward at msd.gatech.edu       |    MATD Laboratory                     |
| (404) 528-7165               |    Atlanta, Georgia  30332             |
-------------------------------------------------------------------------
|     "Reality is showing us that perhaps we should do with nuclear     |
|      power the same thing Keloggs is advocating for Corn Flakes -     |
|      Discover it again for the first time." -- John De Armond         |



More information about the Comp.unix.questions mailing list