CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Script stopped working...[Resolved]: Edit Log



gentoobob
New User

Mar 17, 2018, 6:59 PM


Views: 4336
Script stopped working...[Resolved]

First off, I've never scripted with Perl. I'm a Network Engineer. This script will only work on the 2010 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)...


Code
#!/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);



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


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



(This post was edited by gentoobob on Mar 18, 2018, 10:29 AM)


Edit Log:
Post edited by gentoobob (New User) on Mar 17, 2018, 7:05 PM
Post edited by gentoobob (New User) on Mar 18, 2018, 10:29 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives