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 ...
|
|||||||
| Register | FAQ | Members List | Calendar | Forgotten your password? | Mark Forums Read |
|
|||
|
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.... |
| Sponsored Links | ||
|
|
|
||||
|
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 |
![]() |
| Bookmarks |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| 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 |