LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 05: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, 11:37 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
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



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 05:10 PM
Unexpected results: Difference in Perl Script Behavior between manual and cron runs EnderX Programming 3 12-10-2010 11:42 PM
Perl Script works from command line, but not when evoked by Nagios gfem Linux - General 10 06-05-2008 03:59 PM
Nagios Daemon, PID not found but rc.nagios runs agentc0re Slackware 1 07-03-2007 02:47 PM
php only runs when file is called directly pnh73 Linux - Networking 2 02-20-2004 11:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:44 PM.

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
Open Source Consulting | Domain Registration