slogger has asked for the wisdom of the Perl Monks concerning the following question:
Hi - first post here :-)
I want to read a file thats changing and print the line within that file thats changing - the file isnt being appended to but the lines within the file are changing (hope thats clear!)
I wrote a perl script - works which is good, however as I'm learning perl I'm sure theres a better way of doing this - essentially I'm using a loop, opening file, reading line, extracting data from line, closing file, then sleeping 10 secs then repeating.. instead of doing numerous open/close what would people suggest - I've thought maybe opening, reading then seeking back to start - however that didnt seem to pick updates.. ideas welcome!numpty code follows:-
Thanks, Slogger.#!/usr/bin/perl -w # program to print out cumulative interrupt for network device drivers use strict; #use diagnostics; while (1) { open(PFS,"/proc/interrupts")||die "Cant open file $! \n"; while (<PFS>) { if ( $_ =~ "eth" ) { # change print format here .. overlay and have headers print $_; } # seek(PFS,0,1); # print tell PFS; } close(PFS); sleep(10); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: reading a changing file
by jethro (Monsignor) on Jun 07, 2011 at 13:51 UTC | |
|
Re: reading a changing file
by jethro (Monsignor) on Jun 07, 2011 at 13:49 UTC | |
by slogger (Initiate) on Jun 07, 2011 at 13:57 UTC | |
by jethro (Monsignor) on Jun 07, 2011 at 15:31 UTC | |
|
Re: reading a changing file
by wind (Priest) on Jun 07, 2011 at 16:07 UTC | |
by slogger (Initiate) on Jun 07, 2011 at 16:10 UTC |