473,320 Members | 1,988 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Perl script question

Hi Guys:
Below is my code.
How can I grab the last data of the first column of the output of egrep -n
and store it in a file for comparing it against the last data next time the
script is run.
Is there an easier way of doing this?
Your help is appreciated.

------------------------------
#!/bin/perl

$LOG = "./messages.log";

$SIG{"INT"} = "clean_exit";
$SIG{"TERM"} = "clean_exit";

open(FILE, $LOG) || die "Can not open file $LOG";

# Main loop.
$WORD = "ERROR";
if ($LOG) {
$CURRLINECNT=`egrep -n $WORD $LOG | awk -F":" '{print $1}'`;
# THIS DOES NOT WORK EITHER. What's wrong in the syntax ?
}

# We jump here in case of INT or TERM signals
sub clean_exit {
($signal) = @_;
close FILE;
print "$file closed.\nExiting on signal $signal...\n";
exit;
}
--------------------------
Jul 19 '05 #1
1 3541
George Monappallil wrote:
Hi Guys:
Below is my code.
How can I grab the last data of the first column of the output of
egrep -n and store it in a file for comparing it against the last
data next time the script is run.
Is there an easier way of doing this?
Your help is appreciated.

------------------------------
#!/bin/perl
You are missing

use warnings;
use strict;
$LOG = "./messages.log";

$SIG{"INT"} = "clean_exit";
$SIG{"TERM"} = "clean_exit";
Useless use of double quotes. In this particular case they don't cause any
harm, but that's not always the case.
There is a FAQ about the topic.
open(FILE, $LOG) || die "Can not open file $LOG";
You may want to add the reason _why_ the open failed, see variable $!.
# Main loop.
But there is no loop anywhere here
$WORD = "ERROR";
if ($LOG) {
$CURRLINECNT=`egrep -n $WORD $LOG | awk -F":" '{print
$1}'`; # THIS DOES NOT WORK EITHER. What's wrong in the syntax ?


Gaaaaaack! Why do you fork an external process instead of using Perl's
buildin functions?
Also, if you would have used warnings and strictures, then perl would have
told you quite a few things about this line like e.g that $1 is undefined
because you never had a successful pattern match in your program.

jue

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sam | last post by:
I have a function writen in Perl that takes a name-value list (array) as argument and returns a name-value list (array). My question is: How to call this function from PHP and get the returned...
2
by: Lionel | last post by:
Hi all, I would like having more informations on how we could exchange informations and/or objects between PERL and JAVA. We have a Java programs that open, maintain and close telnet...
3
by: lonelyplanet999 | last post by:
Hi, I'm a newbie to perl and is now studying about perl programming, I read some perl programming tutorials online (enter 'Perl tutorial' at google.com) and also find some sample perl scripts...
1
by: sm00thcrimnl13 | last post by:
if i have windows 2000 and know how to write perl scripts, how to i actuvate the script through perl?
3
by: Jason Miles | last post by:
Hi, I wrote this little script to check to see if our Lotus Notes servers are running, and from the command line it works fine if I type perl notescheck.pl When I invoke the script from a web...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
4
by: Ignoramus6539 | last post by:
There were some strange requests to my server asking for config.php file (which I do not have in the requested location). I did some investigation. Seems to be a virus written in perl,...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
22
by: owlice | last post by:
Greetings! I thought I'd add a little something to a web site, a "tip of the week," and wanted it automated so that if I get hit by a truck (or, more likely, am forgetful), the tip is updated...
3
by: Perl Beginner | last post by:
A few days ago, i was trying to make my perl script an executable (with no success). but that's not the direction of my question (at least not right now). Once i stopped trying to make the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.