Evidently HTTPS stuff changed with LWP version 6. I read Crypt-SSLeay.

I agree with NetWallah that you should be using both strict and warnings. This will spot compile and run time errors. With strictures, each variable has to be declared at first use with "my". I did some of that below to get you started. The use of a while(1) as a loop structure and burying the exit condition in the body is in my opinion a bad idea. More common would be to have the looping exit condition appear right as the loop starts. However, I didn't change that. I did clean up a bit of this $size stuff although I guess that should have been called $n_users? This C-style for loop is a bit weird, but I didn't change that either.

The first step is to clean up any "my" declarations that I might have missed and get this thing to compile cleanly and start running. We can help with any obscure error messages. Then, the next step is to make sure that you are actually getting the first page (i.e. that you ua modifications are working). I added a "die" message if $content is not defined. Stuffing an undefined value into the XML gizmo could cause the GLOB error that you are seeing - maybe. See below and un-comment the print to see the $content and give us enough of it for us to get the idea of what that is (probably don't need the whole thing). Hope this helps.

Update: See the suggestion by hippo at Re: Script stopped working.... Hippo is correct. The response is an object, not a simple scalar. I modified my efforts below with his suggestion and added in the right kind of die message showing the response->status if the req did not succeed. The code doesn't do re-tries but I don't think you need to do that. What I remember from my last LWP effort in 2016, I saw a transient error maybe every 3,000 requests and I implemented re-tries because I had to do a lot of requests. I think it is worthwhile to check if the request succeeded, but I don't recommend mucking with this code any more than necessary. Note: the right place to end the loop may not be if($size<1){} depends upon what the server does when you "run out of valid pages".

use strict; use warnings; use LWP::UserAgent; use LWP::Protocol::https; use XML::Simple; my $xml = new XML::Simple; my @userdata; my $userName = ‘user’; my $passwd = ‘password’; my $page = 1; #Get Unity subscriber data from cucxnpub one page at a time, 2000 reco +rds to a page while(1) { my $url="https://cucxnpub/vmrest/users?rowsPerPage=2000\&pageNumber= +$page"; my $ua = LWP::UserAgent->new(ssl_opts => { SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, verify_hostname => 0,}); my $header = HTTP::Headers->new; my $req = HTTP::Request->new(GET => $url); $req->authorization_basic($userName,$passwd); $req->content_type('application/xml'); # changed this line in update re: [hippo]'s post # this ain't right #my $content = $ua->request($req) or die "unable to get content for +$url $!"; ### need defined content my $response = $ua->request ($req); #response is an object if ( !($response->is_success)) { die $response->status_line; } my $content = $response->decoded_content; my $data = $xml->XMLin ($content); #print "$content\n"; ### un-comment for to see print of xml documen +t #exit; my $size = @{$data->{User}}; #If we don't get at least one user end the loop if($size < 1) { last; ### <- THIS IS HOW LOOP ENDS } #Build the userdata array, each entry contains "username,extension" my $start = (($page-1) * 2000); my $i; for($i=$start;$i<=$start + $size - 1;$i++) { push(@userdata,"$data->{User}->[$i-$start]->{Alias},$data->{User}- +>[$i-$start]->{DtmfAccessId}"); } $page++; } #Create a timestamp containing year, month, and day my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(t +ime); $year+=1900; $mon++; my $timestamp = sprintf("%4d%02d%02d",$year,$mon,$mday); #Dump the results of the unity query to a file open(UNITY,">/usr/scripts/unityLDAP/$timestamp-unity.csv"); for(@userdata) { print UNITY "$_\n"; } close(UNITY);

In reply to Re: Script stopped working... by Marshall
in thread Script stopped working... by gentoobob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.