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 records 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 document #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(time); $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);