Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Jan 2001 01:56:32 -0600 (CST)
From:      Ryan Thompson <ryan@sasknow.com>
To:        "Justin W. Pauler" <jwpauler@jwpages.com>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: tail
Message-ID:  <Pine.BSF.4.21.0101290128380.35514-100000@ren.sasknow.com>
In-Reply-To: <01012813255100.83352@gateway.drnet.fais.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Justin W. Pauler wrote to freebsd-questions@FreeBSD.ORG:

> I am not sure if this is a command, but if not, I think it would be
> useful. I have often needed to watch output from different commands
> like df, but I have to continously run the command to get the latest
> amount. I was thinking, why couldn't tail do that? Since it can watch
> files for changes and display those, why not for a command?
> 
> I tried tail -f | df -h and could not get it to update. I would
> appreciate your thoughts.

tail -f simply leaves the file open after receiving EOF and waits for more
input.  You've got your logic backwards... You are redirecting the IO of
tail to df, which does not make sense.  df will do its thing and display,
and the command will hang there until you hit an EOF or ^C from the
console, because df is waiting for an EOF from tail, which gets its input
from stdin.  The -f parameter to tail is meaningless in this case.

Something that makes more sense would be df -h | tail -f (i.e., take the
output of df, and send it to tail.  Tell tail to ignore the EOF).  But, if
you read the manpage for tail, you will see that -f is meaningless if the
input to tail is a pipe--which, in this case, it is.  There is no way to
"fix" this feature that I'm aware of without redesigning--and
breaking--the whole concept of UNIX pipes. :-)  Besides, why would df keep
writing to the standard output?  It writes the disk summary once and
exits.

So, as others have hinted, you can't get there from here.  You'd be far
better off running a simple command or loop that displays df continuously.
If you want something really fancy, write a perl script to gather the
stats, store them in a variable, sleep 2 seconds, collect them again, and,
if the new output differs from the old, refresh the display.  Otherwise,
don't bother.  This way, the stats update at MOST every two seconds to
bottleneck the thrashing that would ensue when there is a lot of disk
activity.  And, if there is no change, why redisplay?


This has NOT been tested:

#!/usr/bin/perl

my $old_output = "";

while (1)
{
	$output = `/bin/df -h`;

	if ($output -ne $old_output) # then display the new stats
	{
		print "\n\n-----\n$output";
		$old_output = $output;
	}
	sleep(2);
}


> I am also cc'ing this to stable in cause it is a bug/feature...

Yeah, it's been around for a while :-)



> 
> -jwp
> 
> 

-- 
  Ryan Thompson <ryan@sasknow.com>
  Network Administrator, Accounts

  SaskNow Technologies - http://www.sasknow.com
  #106-380 3120 8th St E - Saskatoon, SK - S7H 0W2

        Tel: 306-664-3600   Fax: 306-664-1161   Saskatoon
  Toll-Free: 877-727-5669     (877-SASKNOW)     North America



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0101290128380.35514-100000>