Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a fast "tail -f" like command 1

Status
Not open for further replies.

schu

MIS
Jun 21, 2001
188
HK
I need a command which acts like tail -f.
Instead it should not go into an endless loop but instead show differences between the current and previous run.

I used awk, and wc methods to store line pointer but method is too slow and uses up quite a lot of IO resources because the file is quite big.

Perl seems to work but still seem to take up alot of CPU resources.



Thanks in advance
 
Write a C programme and lseek() to the correct position in the file?

Annihilannic.
 
Another idea... why not save the previous file size in a variable somewhere, and then calculate the difference between the previous file size and current file size, and use tail -1234c filename where 1234 is difference.

Annihilannic.
 
Nice solution Annihilannic.. That's got style...
something like

Code:
#use a reasonable starting value
DELAY=10
LAST_SIZE=$((`ls -l $1|awk '{print $5}'`-1024 ))

while true
  do
    TAIL_OFFSET=$(( `ls -l $1|awk '{print $5}'` -${LAST_SIZE} ))
    tail -${TAIL_OFFSET}c $1
    LAST_SIZE=`ls -l $1|awk '{print $5}'`
    sleep $DELAY
   done
or one could redirect the ls ouput to a file and read it in from there as well..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top