Remove the $cnt++ from the first if loop and put it outside the if and else loop..
open(INFILE, "$File"); $size = @lines = (<INFILE>); close (INFILE); $cnt = 0; $tail = 10; foreach (@lines) { if (($cnt >($size - $tail)) and (/\berror\b/i)) { print "$_"; #$cnt++; print LOG "xyz log has a problem\n"; &email ("\nxyz log has a problem on $t\n"); exit; } else { print "I am doing great"; print LOG "xyz is working fine\n"; print LOG "No E-mail is being sent\n"; close LOG; exit; } $cnt++; } i havent tested but it should work :-) Urmil -----Original Message----- From: Najamuddin, Junaid [mailto:[EMAIL PROTECTED]] Sent: Friday, August 09, 2002 5:15 PM To: 'Kirby_Sarah'; '[EMAIL PROTECTED]' Subject: RE: Need help Sorry, log file is enclosed please -----Original Message----- From: Kirby_Sarah [mailto:[EMAIL PROTECTED]] Sent: Friday, August 09, 2002 5:04 PM To: '[EMAIL PROTECTED]' Subject: RE: Need help Mabe you could send a sample of the log file as well? -----Original Message----- From: Najamuddin, Junaid [mailto:[EMAIL PROTECTED]] Sent: Friday, August 09, 2002 5:23 PM To: '[EMAIL PROTECTED]' Subject: Need help Hi, Thanks in advance, if someone can help me out I am trying to read the last 10 lines of a log file. If the script finds a word ERROR it should email and log the event. If not then do nothing. Some how the other first part is working If it finds the word ERROR it does what needs to be done but when it do not find the word it doesn't do anything I am about to pull my hair. Can some one help me please thanks junaid open(INFILE, "$File"); $size = @lines = (<INFILE>); close (INFILE); $cnt = 0; $tail = 10; foreach (@lines) { if (($cnt >($size - $tail)) and (/\berror\b/i)) { print "$_"; $cnt++; print LOG "xyz log has a problem\n"; &email ("\nxyz log has a problem on $t\n"); exit; } else { print "I am doing great"; print LOG "xyz is working fine\n"; print LOG "No E-mail is being sent\n"; close LOG; exit; } } } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]