http://qs321.pair.com?node_id=1211177


in reply to Script stopped working...

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);