LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-11-2012, 06:36 AM   #1
nicko18
LQ Newbie
 
Registered: Apr 2012
Posts: 1

Rep: Reputation: Disabled
Angry Perl script runs in terminal but not when called by nagios


We are trying to monitor a VPN using a plug-in called “check_vpn.pl” downloaded from the nagios exchange. We are encountering difficulties with the script. When we run the script in the terminal it works however it brings up an error with the nagios core meaning that when nagios calls the script there is an error. The error seems to be in this section of the script:

# Create SNMP Session

($session, $error) = Net::SNMP->session(-hostname=>$host,-community=>$community,-port=>161);
#die "session error: $error" unless ($session);
if (! defined $session){
print "session error: $error";
exit($STATUSCODE{'UNKNOWN'});
}

# Walk sonicSAStatPeerGateway for list of active session OIDs

$result = $session->get_table(-baseoid => $sonicSAStatPeerGateway);
#die "request error: ".$session->error unless (defined $result);
if (! defined $result){
print "request error: ".$session->error;
exit($STATUSCODE{'UNKNOWN'});
}

We can run the script in the terminal using the command

nagios@nagios-virtual-machine:~$/usr/local/nagios/libexec/xxx.x.xxx -C xxxxx -V xxxxx
Which gives the output:

Use of uninitialized value in print at /usr/local/nagios/libexec/check_vpn.pl line 59.
index of oids 8
splits 2
data index .439300970
getdata HASH(0x2020d88)
datatable 195.11.xxx.xxx
splits 2
data index .636748606
getdata HASH(0x2020680)
datatable 213.123.xxx.xxx
splits 2
data index .1197858815
getdata HASH(0x2020bc0)
datatable 83.100.xxx.xxx
splits 2
data index .3221980697
getdata HASH(0x2025118)
datatable 87.102.xxx.xxx
splits 2
data index .3331040650
getdata HASH(0x201abf8)
datatable 213.249.xxx.xxx
splits 2
data index .3381330750
getdata HASH(0x20205f0)
datatable 213.123.xxx.xxx
splits 2
data index .3427044043
getdata HASH(0x2020e30)
datatable 94.72.xxx.xxx
splits 2
data index .3741549102
getdata HASH(0x201ac70)
datatable 87.102.xxx.xxx
namedata HASH(0x2020740)
name !xxxxxxxxxx!
passed VPN Name !xxxxxxxxx!
namedata HASH(0x2020cb0)
name !xxxxxxxxxxx!
passed VPN Name !xxxxxxxxx!
namedata HASH(0x201abf8)
name !Batty!
passed VPN Name !xxxxxxxxxx!


Can anyone help!??
 
Old 04-11-2012, 12:37 PM   #2
MensaWater
Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 6,028
Blog Entries: 5

Rep: Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791Reputation: 791
Runs at command line but doesn't run when...

Any time this occurs the most likely issue is environment. When you login you are invoking things like /etc/profile, /etc/bashrc, /etc/bashprofile, $HOME/.profile, $HOME/.bashrc and/or $HOME/.bash_profile to condition your environment. These things set many environment variables chief among which is $PATH which tells it where to look for executables when you give a short name. (For example if the ls command is in /bin your PATH variable would need to include /bin for you to be able to just type "ls" rather than having to type "/bin/ls" every time.) However there are other important variables as well. When you run Nagios (or cron or any other background process) it isn't logging in so typically does NOT invoke the above files. That means you have to insure the background process knows what environment settings it should have - the best way to do that is to include them in the script.

So if you add a line to the script to output the env to a file and run it from command line then again from Nagios you can find what the environmental differences are between the two runs.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sshfs in bash script - won't run in called terminal? basd Linux - General 3 03-17-2012 06:10 PM
Unexpected results: Difference in Perl Script Behavior between manual and cron runs EnderX Programming 3 12-11-2010 12:42 AM
Perl Script works from command line, but not when evoked by Nagios gfem Linux - General 10 06-05-2008 04:59 PM
Nagios Daemon, PID not found but rc.nagios runs agentc0re Slackware 1 07-03-2007 03:47 PM
php only runs when file is called directly pnh73 Linux - Networking 2 02-20-2004 12:54 PM


All times are GMT -5. The time now is 03:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration