LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-19-2010, 04:55 PM   #1
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Rep: Reputation: 15
NRPE output issue


I have the script below running on a remote server. When its run command line, the correct output returns, which is 5. But when executed with nrpe from the Nagios server, it always returns 0. Im guessing the line with the wc -l is not interpreting with NRPE. What am i missing?

This is to tell how many drives are avail BTW.

#!/bin/sh
#
STATE_OK=0
STATE_CRITICAL=2
STATE_WARNING=1


y=`/usr/openv/volmgr/bin/vmoprcmd -d ds | grep "TLD " | awk '{print $3}' | wc -l`

if [ $y == 0 ]
then
echo "CRITICAL: $y drives availible"
exit $STATE_CRITICAL
fi

echo "OK: $y drives avail"
exit $STATE_OK
~
 
Old 08-19-2010, 05:06 PM   #2
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
Try this instead;


#! /bin/sh
#
STATE=$(/usr/openv/volmgr/bin/vmoprcmd -d ds|/bin/grep "TLD "|/bin/awk '{print $3}'|wc -l)
STATE_OK=0
STATE_CRITICAL=2
STATE_WARNING=1

if [ ${STATE} -eq 0 ]; then
print "CRITICAL: ${STATE} drives availible"
exit $STATE_CRITICAL
else
print "OK: ${STATE} drives avail"
exit ${STATE_OK}
fi


Note that you want to use the full path to the binaries in a script like this (esp. if it runs as root)

Also "print" (rather than "echo") *should* be a built-in shell function (rather than something in /bin or /usr/bin, YMMV).

EDIT: added the missing "| wc -l"

Last edited by xeleema; 08-19-2010 at 06:24 PM.
 
Old 08-19-2010, 05:32 PM   #3
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 97
A little feedback...I like that you changed "y" to something more descriptive,
however I think "NUMBER_OF_DRIVES" is a better descriptor than "STATE" in this
case. Also, running "type print" shows that it's not a built in shell function
for /bin/sh.

Try xeleema's method with a couple of updates:
Code:
#! /bin/sh
#
NUMBER_OF_DRIVES=$(/usr/openv/volmgr/bin/vmoprcmd -d ds|/bin/grep "TLD "|/bin/awk '{print $3}'|/usr/bin/wc -l)
STATE_OK=0
STATE_CRITICAL=2
STATE_WARNING=1

if [ $NUMBER_OF_DRIVES -eq 0 ]; then
  echo "CRITICAL: $NUMBER_OF_DRIVES drives availible"
  exit $STATE_CRITICAL
else
  echo "OK: $NUMBER_OF_DRIVES drives avail"
  exit ${STATE_OK}
fi

Last edited by carltm; 08-19-2010 at 06:18 PM. Reason: missed the "|/usr/bin/wc -l" bit
 
1 members found this post helpful.
Old 08-19-2010, 05:50 PM   #4
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
carltm,

Nice tweaks! Thanks!
Sorry about the print versus echo non-sense. I was sitting in ksh and not Bourne sh when I checked.

investmentbnker75,
It's been a while since I've messed with NRPE. Does it have to be a Bourne shell script? Would it take a full-blown bash script?
(quite a few built-ins, there).
 
Old 08-19-2010, 05:55 PM   #5
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 97
Yes, it could be any kind of script or program that sends output
and has an exit status. Although it would work with bash, I
recommend using sh, since that is more portable. Anything written
in sh will run in bash, but not the other way around.
 
Old 08-19-2010, 06:02 PM   #6
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
Sure anything but perl or ksh Thanks for the help guys ill try out the suggestions and post back right away, as i need to resolve this issue.
 
Old 08-19-2010, 06:16 PM   #7
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
Heres what the output is showing:

[root@stand.edu] ./test
./test: line 8: [: too many arguments
OK: TLD
TLD drives avail

Its not telling me the number of drives avail, just TLD. The output should read OK: 5 drives avail, or Critical: 0 drives avail when run.

Thanks,
 
Old 08-19-2010, 06:19 PM   #8
carltm
Member
 
Registered: Jan 2007
Location: Canton, MI
Distribution: CentOS, SuSE, Red Hat, Debian, etc.
Posts: 703

Rep: Reputation: 97
I just edited the code above. We missed the "|/usr/bin/wc -l" part.
 
Old 08-19-2010, 08:55 PM   #9
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
Uggg! still same issue. Command line, it works on the remote server. It returns: OK: 5 drives avail.

But when run through nrpe on the monitoring server, it returns critical: 0 drives avail. It cant read the actual number that is being returned for some reason.

everything looks good, so i am stumped! Has to be something to do with the line:

NUMBER_OF_DRIVES=$(/usr/openv/volmgr/bin/vmoprcmd -d ds|/bin/grep "TLD "|/bin/awk '{print $3}'|/usr/bin/wc -l)

A different version of this script i found at the link below, which has the same issue. I feel if i am able to return the number of avail drives another way maybe that will resolve the issue?

http://exchange.nagios.org/directory...Drives/details

Thanks for the help guys! Hopefully this can be solved.
 
Old 08-20-2010, 02:42 PM   #10
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
Anyone? Anyone? Bueller? Bueller?
 
Old 08-20-2010, 06:58 PM   #11
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
I'm setting up Nagios right now so I can mess with this and try to figure it out, too.
Gimme a few hours (course, at this rate, I might need a whole day or two)
 
Old 08-21-2010, 03:59 PM   #12
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
Thanks for doing spending the time to help with this xeleema, let me know if you need help with the setup.
 
Old 08-21-2010, 06:22 PM   #13
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 252Reputation: 252Reputation: 252
Okay, here's what I've learned so far;

I've had to pull up the Veritas Netbackup Commands guide for version 6.5 (in PDF format) in order to find out if there's a syntax problem with your 'vmoprcmd -d -ds' command.

However, I'm pretty sure you need a few more environment variables setup in order for Netbackup commands to work just right.
So I have a few more questions for you;

1) You're NPRE setup is using it's own account, or 'root'?
2) What account does all of your Netbackup stuff usually run under? (I know most people setup a separate account so they can do privlege separation)
3) If you have a diff account for your Netbackup stuff, what's the default shell & environment setup like? Anything in it's ~/.profile or ~/.kshrc or ~/.bashrc or ~/.bash_profile that could be specific to it?

4) When you run the "/usr/openv/volmgr/bin/vmoprcmd" command (and it works), what account are you? You might have to run "env" within that account, then "su -" to the NPRE account and do an "env" there, then compare the results.

Something is just not clicking with this. I've got a similar thing setup, and it's working (however, every account has the same global profile on my boxen).

Last edited by xeleema; 08-21-2010 at 06:24 PM.
 
Old 08-21-2010, 09:33 PM   #14
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
Quote:
Originally Posted by investmentbnker75 View Post
y=`/usr/openv/volmgr/bin/vmoprcmd -d ds | grep "TLD " | awk '{print $3}' | wc -l`
You can use grep -c to print a count of matching lines instead of wc -l.
 
Old 08-22-2010, 12:05 PM   #15
investmentbnker75
Member
 
Registered: Oct 2007
Location: Eastern Seaboard
Distribution: CentOS
Posts: 162

Original Poster
Rep: Reputation: 15
Thanks for the suggestion quanta, but grep -c wont work in this situation.
 
  


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
Nagios Event Handler not running - NRPE: Unable to read output notque Linux - Software 7 04-05-2013 07:27 AM
NRPE: Unable to read output theking2 Linux - Software 4 08-04-2010 05:59 PM
Installing Nagios agent nrpe, problems following nrpe install steps rfreiberger Linux - Newbie 3 04-19-2010 09:43 AM
NRPE: Unable to read output theamrit Linux - General 2 12-03-2008 01:09 PM
Nagios/NRPE issue JF1980 Linux - Security 1 05-18-2006 03:59 PM


All times are GMT -5. The time now is 03:03 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration