Re: performance efficient "tail"



ytoledano@xxxxxxxxx wrote:
> Hi,
> I'm trying to write a script which parses the end of a 1GB log which is
> located on a remote server. Since the server isn't mine, I'm not
> allowed to run any scripts on it. Another problem is that it's
> complicated to use non-default modules since I have no Internet
> connection and using any mobile media requires special permission.
>
> How do I tail and parse the last X rows in the most efficient way,
> using existing modules? I don't mind first saving the "tail"ed text
> into a temp file.
>
> I access the logs at \\<IP>\d$\log, if it matters...

A remarkably similar question was just posted to comp.lang.perl.misc.

I would suggest using the standard Tie::File module, as in:
#!/usr/bin/perl
use strict;
use warnings;
use Tie::File;

tie my @file, 'Tie::File', '\\<IP>\d$\log'; #fix this line, obviously.
process_lines(@file[@file-25 .. $#file]);

sub process_lines {
my @lines = @_;
#do whatever you need to do with the last 25 lines of the file...
}
__END__

Paul Lalli

P.S. I'm relatively willing to bet David will have a better looking
solution using IO::All...

.



Relevant Pages

  • performance efficient "tail"
    ... I'm trying to write a script which parses the end of a 1GB log which is ... located on a remote server. ... I don't mind first saving the "tail"ed text ...
    (perl.beginners)
  • RE: remote scripting how to
    ... I re-engineered the following script from the example ... if i check taskmanager i can see the exe sitting there on the ... remote server but not doing what its supose to do, ... > will launch a file remotely on a machine, or copy the file to launch on the ...
    (microsoft.public.windows.server.scripting)
  • Re: Renaming over SCP
    ... Kristian Domke wrote in ... I have to write a script, ... > files onto a remote server via scp and then has to rename them ... > I don't want through the hell of scripting sftp, ...
    (alt.os.linux.suse)
  • RE: Help with SSH
    ... OK before you ask your script to do it's thing. ... Subject: Help with SSH ... a command through ssh on a remote server. ... public keys and have copied the public key to the remote server to the ...
    (RedHat)
  • CreateObject("Excel.Application", )
    ... I start the script as a user with admin right on the remote server. ... The excel is installed on the server. ... Set objSheet = objExcel.ActiveWorkbook.WorkSheets ...
    (microsoft.public.scripting.vbscript)