Results 1 to 6 of 6
Threaded View
-
02-09-2012, 09:17 AM #1Junior Guru
- Join Date
- Oct 2004
- Location
- Celebration, Florida
- Posts
- 209
Help with Bash Monitoring Script...
Good morning all.
While I know PHP, HTML, Java programming and can handle most linux tasks, I'm stuck on a bash script, and am hopeful for a little help.
Currently, we have two linked services (service1 and service2) running on one of our servers. Together, those provide access to an online conferencing system. Randomly and very infrequently, one of the services stop--usually service2--making the service completely unavailable. Since the services are linked, stopping and starting service1 (see below) restarts both.
Therefore, we set up a cron that runs a bash script every ten minutes to make sure that the service is running and, if it's not, attempts a restart. The script checks two things--the results of the "service status" command for each service and the availability and response of port 9000--the port that service1 uses to provide the conferencing access.
However, despite these checks, the service is still occasionally failing without being automatically restarted. So, my question to you is, based on the information above and the bash script below, can you think of anything that we can add to the bash script that would do a better job of monitoring the service and restarting it if necessary? Is there a third check that we could add that would further help catch outages? Finally, with the organization of the script, is the port check being run correctly?
The script is below... and thanks!
------
SERVICE1=`/sbin/service service1 status | grep -c "service1.*is running"`
SERVICE2=`/sbin/service service2 status | grep -c "service2.*is
running"`
(echo >/dev/tcp/localhost/9000) &>/dev/null
if [ $? -eq 0 ]; then
if [[ "$SERVICE2" == "0" || "$SERVICE2" == "0" ]]; then
/sbin/service service1 stop
sleep 10
/sbin/service service1 start
TO="XXX@xxxx.com"
echo "SERVICE `date`" | /bin/mail -s
"SERVER ALERT: RESTART" "$TO" -c "$CC"
fi
else
/sbin/service service1 stop
sleep 10
/sbin/service service1 start
TO="XXX@xxxx.com"
echo "PORT `date`" | /bin/mail -s "SERVER ALERT:
RESTART" "$TO" -c "$CC"▒ Richard C. Hay - Celebration, Florida
▒ Web Application Development, Graphic Design & Organization Management Services
Similar Threads
-
[Bash Script] How to set up redirect of script output within script
By 96mb in forum Programming DiscussionReplies: 2Last Post: 07-17-2011, 09:10 PM -
Bash/perl/python etc. script for Adaptec raid card monitoring ?
By WebHostDog in forum Hosting Security and TechnologyReplies: 0Last Post: 12-07-2010, 09:31 PM -
How to write bash script for round-trip email monitoring
By sallyanne in forum Hosting Security and TechnologyReplies: 0Last Post: 02-20-2010, 02:28 PM -
Can .htaccess call a script (e.g. a bash .sh script)?
By Kadence in forum Hosting Security and TechnologyReplies: 7Last Post: 03-26-2008, 03:59 PM -
bash comman/bash script
By getbusy in forum Hosting Security and TechnologyReplies: 2Last Post: 12-25-2004, 06:50 PM