• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

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;
}
0
MAXcom
Asked:
MAXcom
1 Solution
 
GnissmanCommented:
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
0
 
bigbedCommented:
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..
0
 
bigbedCommented:
Oops, that first line should be:
@coms = split /\n/, $com;
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MAXcomAuthor Commented:
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;
}
0
 
MAXcomAuthor Commented:
Adjusted points to 100
0
 
bigbedCommented:
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...
0
 
bigbedCommented:
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..
0
 
MAXcomAuthor Commented:
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!
0
 
ozoCommented:
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?
0
 
MAXcomAuthor Commented:
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?
0
 
bigbedCommented:
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.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now