Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

First off, I've never scripted with Perl. I'm a Network Engineer. Script below was not created by me, but by an ex employee years ago. This script will only work on a 2011'ish Debian box. We wanted to migrate the script to a new Oracle linux (redhat) VM server. The Debian box was using Perl 5.10. and the Oracle box is using 5.16. We downloaded the modules that was being used in the script but the script will no longer work on the new linux VM. The script accesses Cisco's Call Manager (phone system), it pulls data off the pages. It then parses it (XML) into two columns, users and extensions, and dumps it into a .CSV file.

When this script is ran on the new linux VM, it gives an error trying to access the URL. I found that it was getting denied for two reasons 1) authentication 2) SSL Cert. So after troubleshooting, I learned that I needed to use LWP::UserAgent, not LWP::Simple (or at least I think thats the case). Once I got the UserAgent set up correctly to log in and ignore the SSL cert, I was able to access the site. Then I learned that something with the XML::Simple wasn't working right on the new linux VM. I keep getting a "Not a GLOB reference" error. I've gone as far as trying to get Data::Dumper to work. I'm at a complete lost at this point. To be honest, I can't seem to grasp this GLOB reference or where in the script is the true problem.

Glob error I get..."Not a GLOB reference at /usr/share/perl5/vendor_perl/XML/SAX/PurePerl/Reader/UnicodeExt.pm line 10."

I do not know if something has changed in the versions of code or modules from the old Debian linux box and the newer Oracle linux VM. Any help would be greatly appreciated.

I will list the original script, then list what I have modified.

---Original (works ONLY on the Debian linux Perl 5.10 box)...

#!/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 reco +rds 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);

--Modified by me, I get at it to login to the site but get the GLOB error mentioned above...

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 reco +rds 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);

In reply to 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-03-28 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found