Perl Script Help Needed

I need this script to be able to check both IPs that are given to it and exit with an OK... if one of those expected IPs is returned.

The script is run like this:

/bin/dns_checker.pl -s 69.34.55.66 -q htt.jababa.com -e 69.44.56.33,45.47.43.55

Right now, the script is failing, but when I only specify one IP it passes for both of the IPs.

basically, i want this dns query script to pass if it finds just one of the IPs in the list of IPs given to it. the list of IPs given is what i bolded.

thank you guys

#use strict;
use Getopt::Long;
use utils qw(%ERRORS);
use vars qw($opt_V $opt_h $opt_H $opt_w $opt_c $warning $critical);


my $PROGNAME = "check_dns";
my $VERSION = "Beta 1";
my $query = "/usr/bin/host";

sub messages();

Getopt::Long::Configure('bundling');
GetOptions
        ("V"   => \$opt_V, "version"    => \$opt_V,
         "h"   => \$opt_h, "help"       => \$opt_h,
         "q=s" => \$opt_q, "query=s" => \$opt_q,
         "s=s" => \$opt_s, "server=s" => \$opt_p,
         "e=s" => \$opt_e, "expected=s" => \$opt_e);


messages();
if ($opt_V) { print $Messages{Version} and exit $ERRORS{'UNKNOWN'}; }
if ($opt_h) { print $Messages{Usage} and exit $ERRORS{'UNKNOWN'}; }
print $Messages{Files} and exit unless (-x $query);
unless ($opt_q && $opt_s) { print $Messages{Usage} and exit $ERRORS{'UNKNOWN'}; }
my $response = `$query $opt_q $opt_s`;
my @response = split('\n', $response);
my @expected = split(',', $opt_e);
my $success = '';
my $fail = '';
my $critical = '';
my $timeout = '';
messages();
@expected = sort(@expected);
IP: foreach my $ip (@expected) {
        my $found = 0;
        foreach (@response) {
        print $Messages{'Timeout'} and exit $ERRORS{'CRITICAL'} if /connection timed out/;
        print $Messages{'Failure'} and exit $ERRORS{'CRITICAL'} if /not found/;
        #$found = 1 and last if /$opt_q has address $ip/; # This doesnt work because the 'host' command resolves the query string to it's alias
        $found = 1 and last if /has address $ip/;
        }
        $success .= "$ip, " if $found;
        $fail .= "$ip, " unless $found;
}
chop $success && chop $success;
chop $fail && chop $fail;
messages();
print $Messages{'Warning'} and exit $ERRORS{'WARNING'} if $fail;
print $Messages{'Ok'} and exit $ERRORS{'OK'} if $success;
print "Unknown Output\n" and exit;

sub messages () {
%Messages = (   'Files'         => "make sure $query exists and is executable.\n",
                'Timeout'       => "Connection Timed Out, DNS Unavailable!.\n",
                'Failure'       => "Critical: $opt_s returned $opt_q not found.\n",
                'Version'       => "$PROGNAME Version: $VERSION\n",
                'Ok'            => "Ok: $opt_s returned $success on query for $opt_q.\n",
                'Warning'       => "Warning: $opt_s did not return $fail on query for $opt_q.\n",
                'Usage'         => "Usage: $PROGNAME -s <server> -q <query> -e <expected>\n"
                                        ."\t<server> = DNS Server to query\n"
                                        ."\t<query> = DNS record to query\n"
                                        ."\t<expected> = comma seperated lists of expected IP's\n" );
}

wow what a mess!
what is the point of $found?

you are doing $found = 1 and last

so $success .= "$ip, " if $found; never gets done

i didn't write the script. dont know perl all that well at all. so i dont know what to do with this script to get it to do what i want, which i think is simple.

i just want to be able to check if one of two IPs that I pass to this script is returned, and if so, exit with an OK. if both of the IPs passed to the script isn't returned in the query, then exit with a warning,critical or anything else negative.

I'm guessing no one really knows how to modify this script? :frowning:

First: don't bump up your thread.
Second: we're not here to do your work.

Third: Getopt::Long supports the automatic truncating of options down to the unique part of the option, so you don't really have to specify the one-letter options yourself. See Case and abbreviations in perldoc Getopt::Long
Fourth: Getopt::Long supports arguments with multiple values by using an array-ref. See Options with multiple values in the documentation, including an example on how to mix that with lists of arguments separated by commas.