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:
Strange hostname on apache

 



digioleg54
User

May 2, 2017, 7:07 AM

Post #1 of 9 (1085 views)
Strange hostname on apache Can't Post

I have a small script

Code
#!/usr/bin/dwebenv perl 

#use lib "/vhosts/dw18637/lib/web/";

use DBI;
use DBD::Oracle;
use Spreadsheet::ParseExcel;
use File::Basename;
use strict;
use warnings;

my($lib_path,$data_path);
BEGIN{
$lib_path=$ENV{'DWEB_SITE_PATH'};
$data_path=$ENV{'DWEB_SITE_CGI_DATADIR'};
}
use lib $lib_path.'/lib/web';
print "Content-type: text/html\n\n";
my $host;
eval {
$host = hostname();
};

if ($@) {
print "1..0\n" if $@ =~ /Cannot get host name/;
} else {
print "1..1\n";
print "# \$host = $host\n";
print "ok 1\n";
}


the hostname is nyginwebnp37. The apache is on Linux. Is it a Linux name or apache?

Thanks


FishMonger
Veteran / Moderator

May 2, 2017, 8:55 AM

Post #2 of 9 (1081 views)
Re: [digioleg54] Strange hostname on apache [In reply to] Can't Post

Where is the hostname() function being defined?

Assuming it's from one of the standard cpan modules such as Sys::Hostname, then it would be returning the hostname of the OS.


digioleg54
User

May 2, 2017, 9:48 AM

Post #3 of 9 (1074 views)
Re: [FishMonger] Strange hostname on apache [In reply to] Can't Post

No, it is in the module
File::Basename


Laurent_R
Veteran / Moderator

May 2, 2017, 10:16 AM

Post #4 of 9 (1071 views)
Re: [digioleg54] Strange hostname on apache [In reply to] Can't Post

Probably not. The File::Basename module doesn't have a hostname function AFAIK.


digioleg54
User

May 2, 2017, 10:22 AM

Post #5 of 9 (1070 views)
Re: [Laurent_R] Strange hostname on apache [In reply to] Can't Post

Then how the command works?


FishMonger
Veteran / Moderator

May 2, 2017, 11:58 AM

Post #6 of 9 (1060 views)
Re: [digioleg54] Strange hostname on apache [In reply to] Can't Post

What makes you think it's working?

Get rid of the eval block and that if/else block and then call the hostname() function.


Code
#!/usr/bin/dwebenv perl  

#use lib "/vhosts/dw18637/lib/web/";

use DBI;
use DBD::Oracle;
use Spreadsheet::ParseExcel;
use File::Basename;
use strict;
use warnings;

my($lib_path,$data_path);
BEGIN{
$lib_path=$ENV{'DWEB_SITE_PATH'};
$data_path=$ENV{'DWEB_SITE_CGI_DATADIR'};
}
use lib $lib_path.'/lib/web';
print "Content-type: text/html\n\n";

my $host = hostname();
print "hostname:$host\n";


You should then see the error.

Quote
Undefined subroutine &main::hostname called at ....



digioleg54
User

May 2, 2017, 12:07 PM

Post #7 of 9 (1058 views)
Re: [FishMonger] Strange hostname on apache [In reply to] Can't Post

But I don't

1..1 # $host = nyginwebnp37 ok 1


Code
#!/usr/bin/dwebenv perl 

#use lib "/vhosts/dw18637/lib/web/";

use DBI;
use DBD::Oracle;
use Spreadsheet::ParseExcel;
use File::Basename;
use CGI::Carp qw(fatalsToBrowser);
use strict;
use warnings;

BEGIN{
$lib_path=$ENV{'DWEB_SITE_PATH'};
$data_path=$ENV{'DWEB_SITE_CGI_DATADIR'};
}
use lib $lib_path.'/lib/web';
print "Content-type: text/html\n\n";
my $host;
eval {
$host = hostname();
};

if ($@) {
print "1..0\n" if $@ =~ /Cannot get host name/;
} else {
print "1..1\n";
print "# \$host = $host\n";
print "ok 1\n";
}



FishMonger
Veteran / Moderator

May 2, 2017, 12:22 PM

Post #8 of 9 (1054 views)
Re: [digioleg54] Strange hostname on apache [In reply to] Can't Post

If it's working for you, then that means you must have modified one of those modules to include a hostname() function. I can say that because hostname() is not one of Perl's built-in functions.


digioleg54
User

May 2, 2017, 12:36 PM

Post #9 of 9 (1051 views)
Re: [FishMonger] Strange hostname on apache [In reply to] Can't Post

I didn't modify anything. Now with my knowledge to do it. May be when admin installed Perl 24, some packages went with it on Linux

 
 


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

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