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: mod_perl:
snmp and mod_perl

 



exceed
Novice

May 2, 2009, 10:20 AM

Post #1 of 1 (6553 views)
snmp and mod_perl Can't Post

 
SOLVED: Solution: Removed comments at the beginning and had the shebang line as the first line.

Hi

Im having problems running perl scripts that is using Net::SNMP, they just hang or im getting the message "(8)Exec format error".

Below is the messages from the apache error log (when running the snmpTestWeb.pl):

Code
[Sat May 02 18:51:25 2009] [error] [client 127.0.0.1] (8)Exec format error: exec of '/usr/local/apache2/cgi-bin/snmpToolWeb.pl' failed 
[Sat May 02 18:51:25 2009] [error] [client 127.0.0.1] Premature end of script headers: snmpToolWeb.pl
[Sat May 02 19:03:48 2009] [error] [client 127.0.0.1] (8)Exec format error: exec of '/usr/local/apache2/cgi-bin/snmpToolWeb.pl' failed
[Sat May 02 19:03:48 2009] [error] [client 127.0.0.1] Premature end of script headers: snmpToolWeb.pl


When i run the snmpToolWeb.pl i get an internal server error. The script runs without problems from the command-line. Does apache need some kind of snmp support ? I searched google and looked at httpd.apache.org but couldnt find anything about this.

Code for snmpToolWeb.pl

Code
#!/usr/bin/perl -w 

# load the necessary snmp module
use Net::SNMP ;

print "content-type: text/html\n\n" ;

# operative status for interface eth1
my @oid = qw("1.3.6.1.2.1.2.2.1.8.2") ;

my $query = Net::SNMP->session(
hostname => "localhost",
port => 161,
version => "2c",
community => "password"
) ;

# checking if the snmp session was created without problems.
if (!defined($query)) {
print "An error occured while creating the SNMP session\n" ;
}
else
{
print "\nSNMP session created successfully.\n" ;
}

my $oidResult = $query->get_request("1.3.6.1.2.1.2.2.1.8.3") or print $query->error ;

# checking if we got an answer
if (!defined($oidResult)) {
print "\noid was not received\n" ;
}
else
{
print "\noid received\n" ;

# is the interface up or down?
if ( $oidResult->{"1.3.6.1.2.1.2.2.1.8.3"} == 1 ) {
print "\nInterface is UP\n" ;
}
else {
print "\ninterface is DOWN\n" ;
}
}

exit 0 ;


Other perl scripts that are not using any module are working fine, for example a test script that just prints out all the elements in an array. Does someone know why the perl script is not executing correctly ? Any help is appericiated.

The apache configuration for the directory the scripts are executing in is the following:

Code
<Directory "/usr/local/apache2/cgi-bin"> 
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>


The snmpToolWeb.pl has 755 permission bits.


(This post was edited by exceed on May 2, 2009, 10:33 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