nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

Monitor Running Services

This is a discussion on Monitor Running Services within the Shell scripting forums, part of the Development/Scripting category; I found a script on the site for monitoring running services and would like to change it if possible. I ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 06-25-2007, 09:22 PM
Junior Member
User
 
Join Date: Jun 2007
My distro: Red Hat
Posts: 2
Rep Power: 0
barrett.wendt@aquila.com is on a distinguished road
Default Monitor Running Services

I found a script on the site for monitoring running services and would like to change it if possible.

I am trying to monitor sshd and sladp, my netstat output looks like this...

tcp 0 0 my-ip-address:22 0.0.0.0:* LISTEN 2822/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2638/sendmail: acce
tcp 0 0 :::35747 :::* LISTEN 3776/httpd.worker
tcp 0 0 :::389 :::* LISTEN 4114/ns-slapd

I think the problem is that httpd and slapd are listening on all IP's not a single IP and the script is only filtering one :

So here is the modified script...

#!/bin/bash
# Shell script to monitor running services such as web/http, ssh, mail etc.
# If service fails it will send an Email to ADMIN user
# -------------------------------------------------------------------------
# Copyright (c) 2006 nixCraft project <http://www.cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit Bash shell scripts directory for Linux, FreeBSD, Solaris, UNIX for more information.
# ----------------------------------------------------------------------
# See URL for more info
# Processing the delimited files using cut and awk | nixCraft
# ---------------------------------------------------
# service port
ports="22 389 35747"
# service names as per above ports
service="sshd ns-slapd httpd "
# No of services to monitor as per (above ports+1)
SCOUNTER=3
#Email id to send alert
ADMINEMAIL="root@localhost"
# counter
c=1
echo "Running services status:"
# use sudo if you want i.e. sudo /bin/netstat
/bin/netstat -tulpn | grep -vE '^Active|Proto' | while read LINE
do
sendMail=0
# get active port name and use : as delimiter
t=$(echo $LINE | awk '{ print $4}' | cut -d: -f2)
[ "$t" == "" ] && t=-1 || :

# get service name from $services and : as delimiter
sname=$(echo $service | cut -d' ' -f$c)
sstatus="$sname: No"
# now compare port
for i in $ports
do
if [ $i -eq $t ]; then
sstatus="$sname: Ok"
sendMail=1
fi
done
# display service status as OK or NO
echo "$sstatus"
#next service please
c=$( expr $c + 1 )
[ "$sendMail" == "0" ] && echo $sstatus | mail -s "service down $sstatus" $ADMINEMAIL || :
# break afer 3 services
[ $c -ge $SCOUNTER ] && break || :
done


Can someone help me get this corrected? Any assistance would be appreciated....
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-25-2007, 10:23 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
My distro: Debian GNU/Linux
Posts: 482
Rep Power: 5
monk will become famous soon enough monk will become famous soon enough
Default

It is recommended that you use Monit software instead of a shell script featured on this site. Vivek has posted nice tutorial using monit and it has ability to check multiple IPS and any port on local or remote port. It can even take action such as if local service sshd / httpd dead just restart the service.

Tutorial - Monitor and restart Apache or lighttpd webserver when daemon is killed | nixCraft
Monit download url - monit

Feel free to hit reply button if you need any further assistance
__________________
May the force with you!
Reply With Quote
  #3 (permalink)  
Old 06-25-2007, 10:24 PM
Junior Member
User
 
Join Date: Jun 2007
My distro: Red Hat
Posts: 2
Rep Power: 0
barrett.wendt@aquila.com is on a distinguished road
Default

Thanks Monk for the reply, I will give Monit a shot...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
List Services Linux Running raj Getting started tutorials 4 03-28-2008 04:55 PM
Services need to be stat & stopped on CentOS / RHEL Cluster raj Linux software 0 09-01-2007 01:11 PM
Useless services in CentOS VDS/VPS meowing Web servers 6 06-02-2007 06:34 PM
Enable or disable services in Debian Linux raj Linux software 1 01-25-2007 04:00 AM
Which Linux network services pose a security threat? chimu Linux software 2 07-20-2006 07:59 PM


All times are GMT +5.5. The time now is 08:49 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36