Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


perl script writing empty file, sometimes HELP PLEASE

Posted on 2000-05-04
Medium Priority
Last Modified: 2010-03-05
I have a very annoying and troubling problem.

I have a perl script which calls a another cgi script from ups.com The script on ups.com just sends back a raw html stream which the perl script then parses, and writes out the results to a temp file on my server.

What is happening is about %80 of the time, the temp file is blank. I've tested the script on UPS.com and it never timed out once or sent back blank results once. So i dont think the problem is with ups.

What i really dont understand is why it works sometimes, and not other times. I would think it would either work, or not work, not both.

I dont think its a permissions problem on my server (NT4, IIS4, Service pack 5, latest version of perl from activestate) since if the permissions were wrong, the script would either not run, or not be able to write a temp file. but the script is defintely running, and its defintely writing a temp file. Its just writing them blank sometimes.

This script was working before. It stopped working when i replaced my server with a faster machine. So i can only assume something, somewhere, on the new machine isnt set correctly. But i have no clue what that might be.

I have a bulletin board system on the same machine thats all perl based and it seems to be working fine.

I REALLY need some help on this one, sine its been a problem for the last 2 days with no progress at all.

if anyone wants to look at the perl script, please let me know and i'd be more then glad to send it. its about 10k
Question by:merk
  • 8
  • 8
  • 2
  • +1
LVL 16

Expert Comment

ID: 2778416
can you pl send a copy of the script to maneshr@hotmail.com??

LVL 16

Expert Comment

ID: 2778791
go it. currently looking at it.

Author Comment

ID: 2778871
This might turn out to be a problem with ups after all. Their site is down right now so i have no way of testing this script at all. Perhaps they made some changes to the format of their response which caused the script not to capture the results.

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 16

Accepted Solution

maneshr earned 225 total points
ID: 2778896
exactly!! i have been trying for the last 10 mins. i have stripped down version of your code (157 lines) that goes to their site and gets the info you want and does the processing.

here is the stripped version i am using.

here i have added $|++ and switched on the debug mode.

when i do that and run the script from the command prompt i get socket ok and bind ok.

Also i used a further stripped down version of this script (47 lines) to get yahoo's home page. That worked fine!!

so again i think your script is fine. All the same i will wait for the ups site to come up and try the ups.pl script again.


# UPS Socket code
$upsAction = '4';
$upsProduct = '1DM';
$OriginPostalCode = '94555';
$DestZipCode = '94423';
$PackageWeight = '4.2';

$AF_INET = 2;
$sockaddr = 'S n a4 x8';
$port = 80;
$them = 'www.ups.com';
$function = 'GET';              #Type of HTTP
$workFile = '/using/services/rave/qcostcgi.cgi';
$versionInfo = "HTTP/1.0\n\n";

$workString = '?';
$workString .= 'accept_UPS_license_agreement=yes';
$workString .= '&';
$workString .= "10_action=$upsAction";
$workString .= '&';
$workString .= "13_product=$upsProduct";
$workString .= '&';
$workString .= "15_origPostal=$OriginPostalCode";
$workString .= '&';
$workString .= "22_destCountry=$ShipCountry";
$workString .= '&';
$workString .= "19_destPostal=$DestZipCode";
$workString .= '&';
$workString .= "23_weight=$PackageWeight";
$request = "$function $workFile$workString $versionInfo";


($name, $aliases, $proto) = getprotobyname ('tcp');
($name, $aliases, $port) = getservbyname ($port, 'tcp') unless $port =~ /^\d+$/
($name, $aliases, $type, $len, $remoteaddr) = gethostbyname ($them);

$local = pack ($sockaddr, $AF_INET, 0, $localaddr);
$remote = pack ($sockaddr, $AF_INET, $port, $remoteaddr);

if (socket (S, $AF_INET, $SOCK_STREAM, $proto)) {
        print "socket ok\n" if $debug;
} else {
        die "socket: $!\n";

if (bind (S, $local)) {
        print "bind ok\n" if $debug;
} else {
        die "bind: $!\n";

if (connect (S, $remote)) {
        print "connect ok\n" if $debug;
} else {
        die "connect: $!\n";

select (S);
$| = 1;
select (STDOUT);
$| = 1;

print "$request\n" if $debug;
print S "$request\n";

$got_hdr = 0;
while (<S>) {
        print if $debug;
        push @result, $_ if $got_hdr;
        $got_hdr = 1 if /^\s*$/;        # get lines after header
close (S);
# done with socket code

# put the results in simple variables.
foreach $result (@result){
                # get the name/value strings

= split(/%/, $result);
                # list value keyed by numerical index
        if ($time[$j] eq "-1")  { $time[$j]="None"; }
        # add additional profit to ups charges
        if ($add_profit > 0) {$totalchrg[$j]=$totalchrg[$j]+$add_profit; }
        # Translate UPS Product Codes
        if ($ups[$j] eq "1DM")  { $ups[$j]="Next Day Air-AM"; }
        if ($ups[$j] eq "1DA")  { $ups[$j]="Next Day Air"; }
        if ($ups[$j] eq "1DP")  { $ups[$j]="Next Day Air Saver"; }
        if ($ups[$j] eq "2DM")  { $ups[$j]="2nd Day Air-AM"; }
        if ($ups[$j] eq "2DA")  { $ups[$j]="2nd Day Air"; }
        if ($ups[$j] eq "3DS")  { $ups[$j]="3 Day Select"; }
        if ($ups[$j] eq "GNDCOM")       { $ups[$j]="Ground Commercial"; }
        if ($ups[$j] eq "GNDRES")       { $ups[$j]="Ground Residential"; }

        # check for errors

$upsmax = $j;

# build the code snippet that will be exchanged
for ($j=0; $j<$upsmax; $j++){
$htmlcode .= "UPS-$zone[$j]";
$htmlcode .= ",";
$htmlcode .= "$ups[$j]";
$htmlcode .= ",";
$htmlcode .= "$totalchrg[$j]";
$htmlcode .= "\n";

# Write out UPS file
                # get a temporary filename
do {
     $tempfile = $pathstring . int(rand(99999999)) . ".ups";
   } until !(-e $tempfile);

open (OUTPUT, ">$tempfile") || die "Can't open $tempfile for reading ($!) - Che
ck with your ISP";
select (OUTPUT);
print (OUTPUT $htmlcode) || die "Can't write UPS file: $! - Incorrect permissio
ns on cgi-bin
folder \n";
close (OUTPUT);

# redirect to shipping/db connector
# first add the tempfile name to the redirect string

print "content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<title>HELLO WORLD</title>\n";
print "</head>\n";
print "<body>\n";
print "<h2>UPS RESULTS</h2>\n";
print @result;
print "<h3>tester</h3>\n";
print "$htmlcode ";
print "</body>\n";
print "</html>\n";

Author Comment

ID: 2778938
well the reason i am not %100 sure its a probablem with UPS is because yesterday their site was up. And this script was writing empty temp files, instead of writing the results from the UPS site. When i would hit the UPS url myself, it always worked.

So the only thought i have now, is maybe UPS looked ok to me, but maybe something wasnt entirely ok to the script. Maybe the layout or formatting or something minor changed, which caused the script to ignore the results that UPS sends.

Thats the only thing i can think of right now to explain why it would write empty temp files.

When UPS comes back up i'll try it again.
LVL 16

Expert Comment

ID: 2778958
"So the only thought i have now, is maybe UPS looked ok to me, but maybe something wasnt entirely ok to the script. Maybe the layout or formatting or something minor changed, which caused the script to ignore the results that UPS sends."

i think the most likely reason could be the formatting, since you are expecting the results to be % delimited.

anyway as of now (18:48 EST) its still now responding. :-(
hope it has nothing to do with the "I love you" virus!!
LVL 85

Expert Comment

ID: 2779030
Are you sure $SOCK_STREAM = 1; is correct?
You may want to
use Socket;
to import the proper definitions

Author Comment

ID: 2779046
maneshr...if and when ups comes back up i will post the results of what i normally see when i put the url in the browser.

ozo...you just went over my head. no idea what you mean by using socket. I usually know enough about perl to maybe get a rought idea of what a small script is supposed to do. But thats about it.

LVL 16

Expert Comment

ID: 2779091

sounds good!! meanwhile ups.com is still not respodning/slow.
LVL 16

Expert Comment

ID: 2781350
i ran the trimmed down version of your script a few minutes back and it worked fine!!

here are the contents of the .ups file that the script created.

UPS-94423,The Next Day Air Early A.M. service may not guarantee Early AM arriva
l to   94423 United States.,18.25
UPS-102,Next Day Air,18.25
UPS-202,2nd Day Air,8.20
UPS-302,3 Day Select,5.70
UPS-002,Ground Commercial,3.42
UPS-002,Ground Residential,4.42

meanwhile, how is the script behaving at your end??

did it work??

let me know

Author Comment

ID: 2781558
I havent had a chance to test your script out yet. but i had a thought from a problem someone else posted saying he was unable to make a socket call using perl.

I found a way around this problem. I was using the perlis.dll Instead i switched to using the perl.exe and mapped that to the script, and now its working fine.

Does that give you any clue? Why would it work with the exe but not the dll?

Also, the old server, which was using the dll, was perl 5.003. The new server is running perl 5.6

Author Comment

ID: 2806155
Maneshr, i found out the problem was perl itself. There is a glitch within perl 5.6 when making socket connections. I had to install perl 5.22 and now it seems to be working fine.

Considering all the help you gave me i dont want to just delete the question. If you would email me at merk@pacificnet.net, i will post another empty question with the points set to 75 and give you credit for that. I hope that seems fair.

Author Comment

ID: 2806161
This turned out to be a bug within perl itself. I had to install perl 5.22 to get it to work. I would like to give Maneshr though 75 points for the help he gave me.

Author Comment

ID: 2806162
This question has a deletion request Pending
LVL 16

Expert Comment

ID: 2810805
This question no longer is pending deletion
LVL 16

Expert Comment

ID: 2810806
Glad to know that your problem was solved.

i would suggest that you post a question with the title "For maneshr".

i will just answer that Q and you can go ahead & accept the answer.


Expert Comment

ID: 2812106
Community Support has reduced points from 150 to 75

Expert Comment

ID: 2812107

I am reducing the points on this question as asked so merk can award it to the expert for 75 points.

Community Support @ Experts Exchange

Author Comment

ID: 2812141
thanks for the help.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question