nixCraft Linux Forum

nixCraft

Linux / UNIX 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

Linux answers from nixCraft.


Shell scripting You can discuss the shell scripting, request shell scripts and scripting techniques

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 25-06-2007, 08:22 PM
Junior Member
User
 
Join Date: Jun 2007
OS: Red Hat
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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
  #2 (permalink)  
Old 25-06-2007, 09:23 PM
monk's Avatar
Senior Member
User
 
Join Date: Jan 2005
Location: Tibet
OS: Debian GNU/Linux
Posts: 506
Thanks: 0
Thanked 8 Times in 6 Posts
Rep Power: 7
monk has a spectacular aura about monk has a spectacular aura about
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 25-06-2007, 09:24 PM
Junior Member
User
 
Join Date: Jun 2007
OS: Red Hat
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
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


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 Off


Similar Threads

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


All times are GMT +5.5. The time now is 11:22 PM.


Powered by vBulletin® Version 3.8.5 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2010 nixCraft. All rights reserved

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 37 38