Fedora Linux Support Community & Resources Center
  #1  
Old 23rd January 2008, 09:42 AM
machielr Offline
Registered User
 
Join Date: Jul 2007
Posts: 81
Question ping script for nagios

Hi Guys

I am once again looking for assistance.

I am busy reading up on Nagios in order to have the installation properly set up as the person who did oour last installation did not do it properly.

I found a 'ping plugin script' in the book but I felt that there was somehting not right in the script so I tested it...guess what? It didn;t work (as it should)


The script reads as follows:


#!/bin/sh

OUTPUT='ping -c5 server | tail -n2'
if [ $? -gt 0 ]
then
echo "CRITICAL!! $OUTPUT"
exit 2
else
echo "OK! $OUTPUT"
exit 0
fi


This is supposed to do a ping and returns a message accordingly then exits with a specified status.

However, even if I put in a server name or garbage where the server name is supposed to be, it still returns that the ping was successful.

Can someone assist me to identify what is missing in this script?

Thank you
Reply With Quote
  #2  
Old 23rd January 2008, 10:32 AM
BlueC Offline
Registered User
 
Join Date: Aug 2007
Location: Liverpool, UK
Posts: 733
I know nothing about shell scripting but it seemed an interesting problem. From googling a bit, would something like this do for you?

Code:
#!/bin/sh

HOSTS=" localhost google.com yahoo.com"

for HOST in $HOSTS
do
ping -c1 -w1 $HOST > /dev/null

if [ $? -ne 0 ]
then
echo -n "$HOST unreachable on " && date +%d/%m/%Y
else
echo "ping: $HOST OK"
fi

done

exit 0
Simplify or expand it for your needs.
Reply With Quote
  #3  
Old 23rd January 2008, 10:36 AM
BlueC Offline
Registered User
 
Join Date: Aug 2007
Location: Liverpool, UK
Posts: 733
To make that behave a bit more like your original script:

Code:
#!/bin/sh

HOST="google.com"

ping -c5 $HOST > /dev/null

if [ $? -ne 0 ]
then
echo -n "CRITICAL!! $HOST unreachable on " && date +%d/%m/%Y
exit 2
else
echo "OK!! ping: $HOST OK"
exit 0
fi
Needs testing properly, but works for me.

Last edited by BlueC; 23rd January 2008 at 10:42 AM.
Reply With Quote
Reply

Tags
nagios, ping, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Nagios F11 You don't have permission to access /nagios/ on this server. BWDRKR2 Using Fedora 2 4th March 2010 11:06 PM
bash script to check for ping hiberphoptik Using Fedora 3 4th March 2007 02:52 PM
NAGIOS Premature end of script headers: CGI fatturi Using Fedora 0 11th October 2005 09:22 AM
fedora php-ping.php script not working avswamy Servers & Networking 0 19th January 2005 01:08 PM


Current GMT-time: 08:20 (Sunday, 19-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat