how to tail a file in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to tail a file in perl
# 1  
Old 08-03-2010
how to tail a file in perl

Can any one please help why does tail -f does not work in the below code:

Thanks in advance.

Code:
 
#!/usr/bin/perl -w
 
my $path = "/home/cs/logs/";
my $log = "log.txt";

`cd $path`;
`tail -f $log`;

# 2  
Old 08-03-2010
Does this help you?

Code:
#!/usr/bin/perl

use strict;
use warnings;

open my $pipe, "-|", "/usr/bin/tail", "-f", "./SampleLog.log" or die "could not start tail on SampleLog.log: $!";
print while <$pipe>;

# 3  
Old 08-03-2010
Or you could forgo external programs and use File::Tail
# 4  
Old 08-03-2010
Thanks much dahlia. It work!!!

I will also try File::Tail! thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Joining multiple files tail on tail

I have 250 files that have 16 columns each - all numbered as follows stat.1000, stat.1001, stat.1002, stat.1003....stat.1250. I would like to join all 250 of them together tail by tail as follows. For example stat.1000 a b c d e f stat.1001 g h i j k l So that my output... (2 Replies)
Discussion started by: kayak
2 Replies

2. UNIX for Dummies Questions & Answers

tail from one and match it in the other file

Can someone help me to do the following I have two files file one 123456 789012 345678 901234 567890 file two abcdef ghklmn opqrst 901234 567890 uvwxyz (1 Reply)
Discussion started by: genius_not
1 Replies

3. Shell Programming and Scripting

Perl error while using File::Tail

Hi, Can someone help with this PERL code; I am getting this error while running below code: And this is the code: use File::Tail; $file=File::Tail->new("/some/log/file"); while (defined($line=$file->read)) { print "$line"; } I don't usually use PERL therefore I am not... (1 Reply)
Discussion started by: INHF
1 Replies

4. UNIX for Dummies Questions & Answers

Tail command with wildcard file name

Please help with the following command tail -f /appdata/logs/alert_audit517.txt | grep "Sep 02" The problem I have is with the file name "alert_audit517.txt". The 3 digit number at the end of the file name changes, so I need the file name to use a wildcard. Ive tried alert_audit***.txt, but... (5 Replies)
Discussion started by: robertson1995
5 Replies

5. Shell Programming and Scripting

copy tail output to an external file in perl

The below code works to tail client.log file. but I want to copy the output into an external file /home/tail.txt Can anyone please help. #!/opt/bin/perl -w open my $pipe, "-|", "/usr/bin/tail", "/var/log/client.log" or die "could not start tail on /var/log/client.log : $!"; print while... (2 Replies)
Discussion started by: sureshcisco
2 Replies

6. Shell Programming and Scripting

how to read tail -F command output in perl

Hi All, How I will read the output of the tail -F command in perl. I have text file with below contains file1.txt 1 2 3 4 $running=1; sub openLog($) { (my $log) = @_; (1 Reply)
Discussion started by: pravin27
1 Replies

7. Shell Programming and Scripting

how to tail a log file..

Hi All.. I have a log file in which all the backup information is stored. Now i have written a script which get the last line in the backup log file.. ssh -l ora${sid} ${primaryhost} "tail -1 /oracle/$ORACLE_SID/sapbackup/back$ORACLE_SID.log" However i would like to tail the line last... (4 Replies)
Discussion started by: suri.tyson
4 Replies

8. Linux

tail most recent file command

I have only been working with Linux for a few years now so bear with my noob question. I was wondering if there is a way to tail the most recent file that has a file name like 'scrubsncoa%'. There will be at least 2 files in the directory that start with 'scrubsncoa' and a few other different... (2 Replies)
Discussion started by: RyanD
2 Replies

9. Shell Programming and Scripting

tail display ....in perl

hi we have 3 servers and we have a script to monitor cpu usage of all 3 servers and writes into one file on one of the server where we monitor all those servers ( by doing tail -f filename ) so we decided to create script ( perl ) that will read values from this file and display it should be like... (2 Replies)
Discussion started by: zedex
2 Replies

10. Shell Programming and Scripting

Perl - immitate perpetual "tail"

Is there some way I can have a script monitor the newest line of a log file until a certain entry gets placed in the log? Basically I want to start this script, and have it spit up the last 10 lines or so to a browser via AJAX... the AJAX is not my problem though, as I have no idea how to go... (4 Replies)
Discussion started by: jjinno
4 Replies
Login or Register to Ask a Question