Monitor the services by script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Monitor the services by script
# 1  
Old 03-21-2016
Monitor the services by script

I developed for monitoring the network connections among the branch servers as I given below as script.But I don't know how to monitor the services through network script whether the services is running or not. eg : I want to check the postgres service for all the branch servers through network like as this network monitoring.I don't know how to develop as script,Please guide me.


Code:
#!/bin/bash

FilePath="/root/BranchIPMonitoring.txt"
UplistFilePath="/root/Uplist.txt"
DownlistFilePath="/root/Downlist.txt"

rm -rf $FilePath
rm -rf $UplistFilePath
rm -rf $DownlistFilePath

# Here  I mentioned some example ip addresses

BName[1]="branch 1"     IP[1]="192.168.1.13"            BCode[1]="a71"
BName[2]="branch 2"         IP[2]="192.168.1.122"               BCode[2]="a52"
BName[3]="branch 3"             IP[3]="192.168.1.15"            BCode[3]="b43"
BName[4]="branch 4"            IP[4]="192.168.1.50"             BCode[4]="c56"
BName[5]="branch 5"            IP[5]="192.168.1.56"             BCode[5]="d32"
BName[6]="branch 6"            IP[6]="192.168.1.70"             BCode[6]="t34"
BName[7]="branch 7"            IP[7]="192.168.1.100"            BCode[7]="f32"
BName[8]="branch 8"            IP[8]="192.168.1.45"             BCode[8]="32q"
BName[9]="branch 9"            IP[9]="192.168.1.67"             BCode[9]="e54"
BName[10]="branch 10"   IP[10]="192.168.1.26"           BCode[10]="r21"

for (( i=1; i<=10; i++ ))
do
if ping -c 1 -W 1 ${IP[i]} > /dev/null
then
echo " ${BCode[i]}-${BName[i]}-ipaddress ${IP[i]} is up" >> $FilePath
else
echo " ${BCode[i]}-${BName[i]}-ipaddress ${IP[i]} is down " >> $FilePath
fi
done
while :
do
clear
echo " Welcome to our Network Monitoring Utility , Please Choose the Option to continue. "
echo " "
echo "     ---------------------- M A I N - M E N U ---------------------             "
echo " "
echo "     ************************************************************** "
echo " "
echo "    1. How many branch IP connection is up and those details    "
echo " "
echo "    2. How many branch IP connection is down and those details  "
echo " "
echo "    3. Exit                                                     "
echo " "
echo "     ************************************************************** "
echo " "
echo -n "Please select your choice [ 1 to 3 ] :: "
read choice
case "$choice" in
1) cat $FilePath | grep up > $UplistFilePath
   uplistcount=`wc -l $UplistFilePath | cut -c1-2`
   echo " "
   echo " $uplistcount number of Branch Network connections are working fine  "
   echo " "
   cat $FilePath | grep up
   echo " "
   echo "Press [enter] key to continue. . ."
   read enterKey;;
2) cat $FilePath | grep down > $DownlistFilePath
   downlistcount=`wc -l $DownlistFilePath | cut -c1-2`
   echo " "
   echo " $downlistcount number of Branch Network connections are down "
   echo " "
   if  cat $FilePath | grep down
   then   echo " "
   else
   echo " No branch is down "
   echo " "
   fi
   echo "Press [enter] key to continue. . ."
   read enterKey;;
3) echo "Bye $USER"
   exit 1;;
     *) echo "$choice is an invaild option. Please select option between 1-3 only"
     echo "Press [Enter] key to continue. . ."
     read enterKey;;
esac
done


Last edited by kannansoft1985; 03-21-2016 at 03:27 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Script monitor website wth default tomcat script

Hi all, on our application server we have the following script that monitor the status of the website, my problem here is that i have edite the retries from 3 to 5, and the timewait to 120 second, so the script should check 5 times every 2 minutes, and if the fifth check fails it must restart... (0 Replies)
Discussion started by: charli1
0 Replies

2. Infrastructure Monitoring

Searching for Saas Monitor service which monitor my servers which are sitting in different providers

Sorry if this is the wrong forum Searching for Saas Monitor service which monitor my servers which are sitting in different providers . This monitor tool will take as less CPU as possible , and will send info about the server to main Dashboard. The info I need is CPU / RAM / my servers status (... (1 Reply)
Discussion started by: umen
1 Replies

3. Shell Programming and Scripting

Monitor some of network services

Hi I want to write a script for netflow service because my service doesnt send any packet to netflow walker (server). Although the service is started but it does not send any packet to server until i restart the service I want to write a script in order to restart the service... (7 Replies)
Discussion started by: mohsen1366
7 Replies

4. Shell Programming and Scripting

Script to Start services based on dependent services on other AIX machine

Hi, I just started working on a script. After my research, i found a command which can help me: AIM: To build a script which starts the services (Services 1) on server 1 automatically whenever its down. And it has a dependency on other service (Service 2) on Server 2. So my script has to... (4 Replies)
Discussion started by: draghun9
4 Replies

5. Red Hat

Restart of services if port no is changed in /etc/services in RHEL

I had a doubt if any services need to be restarted if port no in /etc/services in an RHEL setup is changed. For eg, the port no of 443 for SSL may need to be changed. I hope my query is clear whether any services need to be restarted if port no in /etc/services is changed. Please revert with... (10 Replies)
Discussion started by: RHCE
10 Replies

6. Shell Programming and Scripting

Need script to restart the services

Hi Guys, I need bash script to restart the service. 1. Disable the service called SASM svcadm disable sasm 2. if service went to maintenance mode then it shuld clear it with below command svcadm clear sasm 3.or else it should restart the mysql service /etc/init.d/mysql stop... (1 Reply)
Discussion started by: bapu1981
1 Replies

7. AIX

How to monitor websphere services down?

if websphere services is down, any unix command or scripts can send alert? (1 Reply)
Discussion started by: rainbow_bean
1 Replies

8. AIX

Startup script and services

Guy's What the exact steps to mention for example this script /usr/start/start.sh to be as start up script , I want it to be automatically started when I reboot the server . (8 Replies)
Discussion started by: ITHelper
8 Replies

9. SuSE

Script to disable services

Hi All, I want to disable bunch of unused services on SLES and RHEL to improve the performance. Since we have more than 100 servers to disable services, I want to do with some script. Any one can give me an idea how to write a script to disable services. Thanks (1 Reply)
Discussion started by: s_linux
1 Replies
Login or Register to Ask a Question