Perl error while using File::Tail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl error while using File::Tail
# 1  
Old 02-09-2012
Perl error while using File::Tail

Hi,

Can someone help with this PERL code; I am getting this error while running below code:
Quote:
./PerlTestFile.pl[4]: use : not found
./PerlTestFile.pl[5]: syntax error at line 5: `('
And this is the code:
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 familiar with PERL coding. 

All I require is to read the end of a log file and write it to another file.

Thanks
# 2  
Old 02-10-2012
Quote:
Originally Posted by INHF
Hi,

Can someone help with this PERL code; I am getting this error while running below code:

Code:
./PerlTestFile.pl[4]: use : not found 
./PerlTestFile.pl[5]: syntax error at line 5: `('

And this is the code:
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 familiar with PERL coding. 
 
All I require is to read the end of a log file and write it to another file.

Thanks
You are trying to run a Perl program as a shell script. Those errors are thrown by your shell.

Do the following:

(1) Find out the path of the "perl" interpreter on your system by using the "type" or "which" commands.

Code:
$
$ type perl
perl is hashed (/usr/bin/perl)
$
$ which perl
/usr/bin/perl
$
$

So, in my system, "perl" lies in "/usr/bin" directory.

(2) Add the shebang at the top of your Perl program, which is nothing by the characters "#!" followed by the path to perl. After adding it, your program should look like this:

Code:
$
$ cat -n PerlTestFile.pl
    1  #!/usr/bin/perl -w
    2  use File::Tail;
    3    $file=File::Tail->new("/some/log/file");
    4    while (defined($line=$file->read)) {
    5        print "$line";
    6    }
$
$

Needless to say, you'd use the path to perl on your system.

(3) Finally, to run the program, feed it to the perl interpreter, like so -

Code:
perl PerlTestFile.pl

Note that the shebang is not required if you are going to invoke your program using the "perl" interpreter, but it is a good practice. And so is the "-w" switch which prints warnings, if any.

On the other hand, if you want to run the Perl program without feeding it to the perl interpreter, then you need the shebang. And if you choose to go that way, then:

(a) keep the shebang
(b) make your file an executable:

Code:
chmod u+x PerlTestFile.pl

(c) and then call it like you would an executable -

Code:
$ ./PerlTestFile.pl

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
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. UNIX for Dummies Questions & Answers

Error message with tail command

Hello, I wrote a script and part of the script, I have a validation to check if the file has <EOF> on the last line of the file. If it does not have a <EOF>, then a message has to be written to a log file. the code snippet shown below works fine, but it writes the below message if the... (1 Reply)
Discussion started by: Vijay81
1 Replies

4. Shell Programming and Scripting

How to tail -f real time file.

How to tail -f real time file. I want to tail file created last time. The server is gen new file Always. . An example file. -rw-r--r-- 1 shinnie tiituck 251M Oct 18 05:39 20111018_00.log -rw-r--r-- 1 shinnie tiituck 251M Oct 18 11:18 20111018_01.log -rw-r--r-- 1 shinnie tiituck... (3 Replies)
Discussion started by: ooilinlove
3 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 tail a file in perl

Can any one please help why does tail -f does not work in the below code: Thanks in advance. #!/usr/bin/perl -w my $path = "/home/cs/logs/"; my $log = "log.txt"; `cd $path`; `tail -f $log`; (3 Replies)
Discussion started by: sureshcisco
3 Replies

7. 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

8. 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

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