Searching for text in a text file using Perl in AIX

Posted on 2007-07-25
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.

use strict;

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

open(LOG, ">$log");

open (FILE, "</u/tmp/sendte.log") || die "Cannot open 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;

Question by:mhorrocks
    LVL 84

    Accepted Solution

    my $found;
       $found ||= /$string1/
     unless( $found ){print LOG "FTP Upload Error\n";}

    Author Comment

    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.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
    FreeBSD on EC2 FreeBSD ( is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now