#!/usr/bin/perl use LWP::Simple; use XML::Simple; my $xml = new XML::Simple; my @userdata; $page = 1; #Get Unity subscriber data from cucxnpub one page at a time, 2000 records to a page while(1) { #Uses ADQuery as the Unity service account my $url = "https://User:password\@cucxnpub/vmrest/users?rowsPerPage=2000\&pageNumber=$page"; my $content = get($url); die "Error getting $url" unless defined $content; my $data = $xml->XMLin($content); $size = @{$data->{User}}; #If we don't get at least one user end the loop if(@{$data->{User}} < 1) { last; } #Build the userdata array, each entry contains "username,extension" $start = (($page-1) * 2000); for($i=$start;$i<=$start + @{$data->{User}} - 1;$i++) { push(@userdata,"$data->{User}->[$i-$start]->{Alias},$data->{User}->[$i-$start]->{DtmfAccessId}"); } $page++; } #Create a timestamp containing year, month, and day ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year+=1900; $mon++; $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); #### use LWP::UserAgent; use LWP::Protocol::https; use XML::Simple; $xml = new XML::Simple; @userdata; $userName = ‘user’; $passwd = ‘password’; $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"; $ua = LWP::UserAgent->new(ssl_opts => { SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, verify_hostname => 0, }); $header = HTTP::Headers->new; $req = HTTP::Request->new(GET => $url); $req->authorization_basic($userName,$passwd); $req->content_type('application/xml'); $content = $ua->request($req); my $data = $xml->XMLin($content); $size = @{$data->{User}}; #If we don't get at least one user end the loop if(@{$data->{User}} < 1) { last; } #Build the userdata array, each entry contains "username,extension" $start = (($page-1) * 2000); for($i=$start;$i<=$start + @{$data->{User}} - 1;$i++) { push(@userdata,"$data->{User}->[$i-$start]->{Alias},$data->{User}->[$i-$start]->{DtmfAccessId}"); } $page++; } #Create a timestamp containing year, month, and day ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year+=1900; $mon++; $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);