cesargarza has asked for the wisdom of the Perl Monks concerning the following question:

I have a script which is passing a ARGV for a hostaddress but i need a dynamic way to take host address automatically. script is something like this
my $store; my $memory; my $temp; my @address; { $address[0] = $ARGV[0]; $address[1] = $ARGV[1]; } my @url; { $url[0] = "http://$address[0]:8161/admin/xml/queues.js +p"; $url[1] = "http://$address[1]:8161/admin/xml/queues.js +p"; } my @xmldata; my $i = 0; foreach (@url) { my $dump; eval { $dump = qx|/usr/bin/curl --user admin:admin -s $url[$i +]|; #$xmldata[0] = XMLin($dump); push(@xmldata, XMLin($dump)); }; if ($@) { print "URL $url[$i] down\n"; } $i++; } my $queue; my $data; my $issuecount = 0; my $issues = ""; my $queueCount = 0;
is there anyway script takes the hostaddress (unlimited) and put in the above URL. as many host address also as many URl......

Replies are listed 'Best First'.
Re: Host address not getting
by kennethk (Abbot) on Sep 26, 2013 at 20:05 UTC
    @ARGV is just an array, like any other.
    my @address = @ARGV; my @url; for my $i (0 .. @address-1) { $url[$i] = "http://$address[$i]:8161/admi/xml/queues.jsp"; }
    where that little bit of code can be written a lot of different ways.
    my @address = @ARGV; my @url = map "http://$_:8161/admi/xml/queues.jsp", @address;
    A review of For Loops and Foreach Loops in perlsyn might be helpful.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      My bad, i think i didn't explain it well. Actually i am working on nagios where i have a group with multiple servers information in the file. Now i have a perl script which basically run and take the information from XML through URL. Instead of i put the hostaddress (http://hostaddress:8161/admin/xml/queues.jsp)as a ARGV, was wondering if perl script take the host address from that file automatically.

        Not familiar with 'nagios', but there certainly shouldn't be any reason Perl can't parse the file and pull the addresses. Can you show us what the file looks like?


        #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        Host address of: http://hostaddress is just not going to "work".
        You need something that will work in a browser.
        Maybe $hostaddress = Google; or something like that.
        Simple "hostaddress" won't work.

        First step is to see the webpage in a browser window before you try to get Perl to do it.

        This "8161" is a port address at a specific web site.

        my ($site) = ARGV; #might work better
        If you ask about a command line parm, then show it in your question.