[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Searching for text in a text file using Perl in AIX

Posted on 2007-07-25
2
Medium Priority
?
448 Views
Last Modified: 2013-11-17
I am having some difficulty with a Perl script file running on AIX.

I am trying to read in a log file and look for the string "File successfully transferred" and if I don't find it, then send an email to me letting me know about the failure

My script is below.  It works if I use the "if" statement, but that is not what I want to know, I only want to know if the string is not found.  When running the below script it finds the string but sends out a bunch of emails anyway like it couldn't find the phrase.  I have tried the "if" "else" approach but get an email about success and failure ( a lot of failures ).

Can anyone assist me?  This is driving me crazy.

#!/usr/bin/perl
use strict;

my $log = '/u/tmp/ftpupload_te.log';
my $emails = "user\@domain.com";
my $subject = "TECO FTP Upload Error";
my $string1 = "File successfully transferred";

open(LOG, ">$log");

open (FILE, "</u/tmp/sendte.log") || die "Cannot open file";

while(<FILE>)
{
        unless($_=~/${string1}/){print LOG "FTP Upload Error\n";}
        unless($_=~/${string1}/){my $ret = `cat "/u/tmp/ftpupload_te.log" | mail -s "$subject" "$emails"`;}
}

close FILE;

close LOG;

exit(0);
0
Comment
Question by:mhorrocks
2 Comments
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 19569742
my $found;
while(<FILE>)
{
   $found ||= /$string1/
}
 unless( $found ){print LOG "FTP Upload Error\n";}
0
 

Author Comment

by:mhorrocks
ID: 19569834
I don't know all that much about scripting, but once I have a script built, I can usually modify it to fit other needs.

Really appreciate your help.  That worked like a charm.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Six Sigma Control Plans
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question