in reply to specific field selection

     "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom

Replies are listed 'Best First'.
Re^2: specific field selection
by javpra (Initiate) on Mar 06, 2008 at 15:34 UTC
    Thank you both so much. I'm impressed with the helpfulness and promptness of this forum. Below is the end result. Of course the last two printf() statements are kind of silly, I was just using them to make sure the script would work. Both of the printf() calls will be changed to system() in order to send out an email notification. There is no SMART equivelant for cciss drivers in FreeBSD so this will keep an eye on things.
    #!/usr/bin/perl use strict; use warnings; my @args; our $F; @args = ("cciss_vol_status /dev/ciss0 > checkstatres.txt"); system(@args); open RESULTS, "checkstatres.txt" or die "can't open datafile: $!\n"; while (<RESULTS>){ my @F=split(/:/, $_); if ( $F[2] =~ /OK./){ printf (" it's okay\n"); } else{ printf (" it's not ok\n"); } }
      In the spirit of helping improve programming skills, please accept these minor criticisms:

      • our $F; is not being used, and is not necessary. What IS being used it my @F...
      • You are separating the declaration and assignment of @args. Proficient perl programmers would combine these as in
        my @args = ("cciss_vol_status /dev/ciss0 > checkstatres.txt");
      • You are not checking to see if your system call was successful. Typical use is :
        system ... or die ....

      Happy programming!

      You could also consider the Net::SMTP (or Mail::SendEasy) modules as an alternative to using system calls to send mail.

           "As you get older three things happen. The first is your memory goes, and I can't remember the other two... " - Sir Norman Wisdom

        Thank you NetWallah, your input is appreciated. I've made the changes so hopefully my script now looks closer to what someone that knows what thery're doing would have done ;-) . I do have one new issue. I'm trying to get the script to email. According to what I read in "Programming Perl" and through Google it should work as is shown below. However the $hostname and $address variables in @email are not being seen. If I "hard code" the hostname and email address the script works fine. Anyone have any more suggestions?
        #!/usr/bin/perl use strict; use warnings; $address = 'user@gmail.com'; my @hostname = ("hostname -s"); my @email = ("echo $hostname array issue | mail -s 'Array problem' $ad +dress"); my @args = ("cciss_vol_status /dev/ciss0 > checkstatres.txt"); system(@args); open RESULTS, "checkstatres.txt" or die "can't open datafile: $!\n"; while (<RESULTS>){ my @F=split(/:/, $_); if ( $F[2] =~ /OK./){ ;; } else{ my $hostname = system(@hostname); system(@email); } } my @args2 = ("rm checkstatres.txt"); system(@args2);