Link to home
Start Free TrialLog in
Avatar of MAXcom
MAXcom

asked on

Whats wrong?

Hi, i just want to say that I am learning because this script's integrity im sure sucks but I think I have the idea. Basically, I am trying to extract the first name, last name and an email from a whois inquiry but it doesnt want to work..why?

#!/usr/local/bin/perl
$checkthis = "bannerweb.com";
&printtop;
&check_com;
&printbot;

sub check_com{
$com = `whois $checkthis`;
print ".\n";
if ($com =~ /No match for/i){} else {&getemailcom;}
}

sub getemailcom{
@coms = $com;
$x = 0;
foreach $strn (@coms){
      $strn = grep {"administrative"} $strn;
      if ($strn eq "administrative") {$x=1;} else {
      if ($x == 1) {
            ($fname,$lname,$mail) = $line=~/(\w+)\W+(\w+).*\s(\S+)/;
            $x = 0; &write;}
            }
      }
}

sub printtop{
   print "Content-type: text/html\n\n";
   print "<html><head><title>Working... just wait.</title></head>\n";
   print "<body bgcolor=#FFFFFF text=#000000>\n";
}

sub write{
$str = $firstname.",".$lastname.",".$mail;
print "$str\n";
}

sub printbot{
   print "</body></html>\n";
   exit;
}
Avatar of Gnissman
Gnissman

What do you mean by "it dosn't want to work"?
Does it return an error if you start it?
Does the whois-call return any values and is it just a matter of matching them the right way?

Any information could help ;-)

Gniss
In function getemailcom() you probably want to do:
@coms = split $com

Also, your use of grep will set $strn to the number of times the word "administrative" appears in the line you are testing.
Perhaps you should do
if ( $strn =~ /administrative/i )
{
   $x = 1;
}
else
.... etc.
Also, the line:
($fname,$lname,$mail) = $line=~/(\w+)\W+(\w+).*\s(\S+)/;

should use $strn instead of $line.

Give that a try..
ASKER CERTIFIED SOLUTION
Avatar of bigbed
bigbed
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MAXcom

ASKER

Ok, here is the script with the changes; I still get the "500 Internal Server Error". I dont get it...

#!/usr/local/bin/perl
$checkthis = "bannerweb.com";
&printtop;
&check_com;
&printbot;

sub check_com{
$com = `whois $checkthis`;
print ".\n";
if ($com =~ /No match for/i){} else {&getemailcom;}
}

sub getemailcom{
$x = 0;
@coms = split /\n/, $com;
foreach $strn (@coms){
      if ($strn =~ /administrative/i)
           {
             $x = 1;
           } else {
      if ($x == 1) {
            ($fname,$lname,$mail) = $strn=~/(\w+)\W+(\w+).*\s(\S+)/;
            $x = 0; &write;}
            }
      }
}

sub printtop{
   print "Content-type: text/html\n\n";
   print "<html><head><title>Working</title></head>\n";
   print "<body bgcolor=#FFFFFF text=#000000>\n";
}

sub write{
$str = $fname.",".$lname.",".$mail;
print "$str\n";
}

sub printbot{
   print "</body></html>\n";
   exit;
}
Avatar of MAXcom

ASKER

Adjusted points to 100
try running:
perl -c <scriptname>
from the command line - this may show up some errors.
Be sure that the perl program *really* resides at /usr/local/bin/perl on your server.
Be sure that the permissions on the script allow the web server to execute it (ie at least 555 permissions).
If you don't have access to the error logs of your web server, ask the sysops if there are any log entries for your script.
Sorry if you feel I'm teaching grandma to suck eggs, but these are things I often overlook...
Also, just try running it from your command line - you'll just get the HTML printed out, but you'll also see if any errors are being generated..
Avatar of MAXcom

ASKER

The people I am hosting with are not letting me get command line access and they will not run it for me. What do I do? The perl path is correct and permissions are 755. No access to log enteries. :( HEELP!
Avatar of ozo
Is
#!/usr/local/bin/perl
the first thing in the program?
does whois exist on the server?
Is it in your path?
Do you have permission to run it?
Avatar of MAXcom

ASKER

Ok, my server was screwed up I called em and they fixed it... some permission thing. It runs now but it doesnt give me any feedback for some reason. It prints the dot so I know it did the whois inquiry and after that nothing happens, i dont get any of the information i want. Am I going about this wrong?
I tried running your script from my command line (had to change the perl path in the first line, but otherwise I changed nothing). I got the following:

Content-type: text/html

<html><head><title>Working</title></head>
<body bgcolor=#FFFFFF text=#000000>
..
Max,Bolotnikov,maxcom@INTERSERV.COM
</body></html>

Is this the sort of thing you're expecting?

We're running apache under Linux, with Perl 5.00503.

Following on from ozo's suggestion, perhaps you need to put in the full pathname to whois in the command, like:
$com = `/usr/bin/whois $checkthis`;

or whatever its path is on your machine.
Again, you may have to ask the sysops what the path is.
Generally in CGIs it is best to put in full pathnames to commands you run within the backticks, for security.