Shell script to notify of service down


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to notify of service down
# 1  
Old 06-06-2014
Shell script to notify of service down

Hi All

I am trying to write a shell script that will notify via email if a particular service is down. What I have so far is a script in
Code:
cron

like his:
Code:
#!/bin/sh
cd /usr/jdk/instances/jdk1.6.0/bin/sparcv9
jps -m

And the output of the above is

Code:
 81529 Jps
  52988 TaskControllerService
  52670 StreamControllerService

But what I would like to receive is an email with the following heading:

Code:
"Service name" "Value"

where
Code:
"Value"

is either
Code:
online

or
Code:
offline

.
# 2  
Old 06-06-2014
Here is one way of doing it:
Code:
#!/bin/ksh

for service in TaskControllerService StreamControllerService
do
        if /usr/jdk/instances/jdk1.6.0/bin/sparcv9/jps | /usr/sfw/bin/ggrep -q "$service"
        then
                print "$service online"
        else
                print "$service offline"
        fi
done > mail_body

mailx -s "Subject" user@domain.com < mail_body

If you don't have ggrep replace that line with:
Code:
if /usr/jdk/latest/bin/sparcv9/jps | grep "$service" 1>/dev/null 2>/dev/null

This User Gave Thanks to Yoda For This Post:
# 3  
Old 06-06-2014
You don't need the GNU utilities version of grep to use the -q option. It has been in the formal standards for more than two decades and in the SVID and X/Open Portability Guides quite a while before there were formal standards for UNIX and UNIX-like system utilities.
# 4  
Old 06-06-2014
Don, the grep in /usr/bin/ on Solaris does not support -q option: grep manual
Code:
/usr/bin/grep [-bchilnsvw] limited-regular-expression
	    [filename]...

# 5  
Old 06-06-2014
It is there in /usr/xpg4/bin/grep and /usr/xpg6/bin/grep. In theory, -q support should have been added to /usr/bin/grep when /usr/xpg4/bin/grep was created (since adding that option would not break any correct use of grep before that option was added), but that didn't always happen.
# 6  
Old 06-09-2014
Hi

It worked fine, after changing the
Code:
if

statement to avoid the
Code:
ggrep

.
Thank you very much
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell script newbie- how to generate service log from shell script

Hi, I am totally a newbie to any programming languages and I just started an entry level job in an IT company. One of my recent tasks is to create a script that is able to show the log file of linux service (i.e. ntpd service) lets say, if I run my script ./test.sh, the output should be... (3 Replies)
Discussion started by: xiaogeji
3 Replies

2. Shell Programming and Scripting

Notify as soon as an error is encountered in a script

Hi, The script below works okay and emails me the log in the end once the script completes but what I'm trying to do is to also notify me via an email as soon as the script encounters any error whatsoever. cat test.list hdisk0 00a6351a2c832da1 rootvg ... (7 Replies)
Discussion started by: mbak
7 Replies

3. Shell Programming and Scripting

Service checking through shell script

I want to check the postgres service for client PC which is remotely placed through shell script , whether the Postgres service is working or not.I don't have an idea to develop this script.Please give me a code. Client PC IP Address: 10.66.1.133 (2 Replies)
Discussion started by: kannansoft1985
2 Replies

4. Shell Programming and Scripting

Bash script to notify when ever any files are changed

Hi the following script let sthe user know whenevr any file is changed inserted or deleted in file system. but i am getting following error while running bash script ## LINUX SYSTEM FILE ARCHIVE NOTIFY ## if ; then echo "Usage '$0 folder waitseconds' " ; exit 1; fi if ; then echo "Folder... (1 Reply)
Discussion started by: programmingzeal
1 Replies

5. Shell Programming and Scripting

Monitoring Tomcat Service with shell script

Hello Forum, I have prepared script to monitor the tomcat status. Following is the script which will monitor tomcat instance. I need little modifcation in the script. My script will grep for process, the output of grep command will analyze by if condition under for loop and will send... (2 Replies)
Discussion started by: ooilinlove
2 Replies

6. Shell Programming and Scripting

Shell script for service

Hi, I want to add an application as a service in Linux(Fedora 12). It should be run always for monitoring my system. It never terminate unless kill it. I wrote this script, put it on /etc/init.d/myapp and added it to run level 2345: #!/bin/bash # # chkconfig: 2345 20 80 # description:... (3 Replies)
Discussion started by: pronetin
3 Replies

7. Shell Programming and Scripting

checking to see if a service is running in a shell script

How can I tell, in a shell script, if a certain service is running? I know how to do this on the command line, but not in a script. Is an error thrown somehow that I can check? Thanks. (6 Replies)
Discussion started by: daflore
6 Replies

8. Shell Programming and Scripting

notify-send does not notify real time

Hi, I am having a little trouble getting notify-send to work the way I would like it to. I am using ubuntu - karmic koala 2.6.31-19-generic #56-Ubuntu SMP So here's the problem run the following commands one after the other. notify-send -i info -t 100000 -- "Hi" "world" & notify-send -i... (3 Replies)
Discussion started by: linuxpenguin
3 Replies

9. Shell Programming and Scripting

How to write a shell script to notify when certain texts appear in a file?

I have a server and occasionally the file mysqld.log would show something like /usr/libexec/mysqld: Disk is full writing './example_com_-_wordpress/wp_statpress.MYD' (Errcode: 122). Waiting for someone to free space... Retry in 60 secs How do I write a simple shell script to check mysqld.log... (1 Reply)
Discussion started by: acider
1 Replies

10. Shell Programming and Scripting

How the first script should notify in case there is no response from second

Hi Experts, I am trying to write a ksh script that it should notify in case there is no response from the other script. I mean to say that I got a.sh and b.sh the execution of b.sh depends on a.sh, so if there is no response from a.sh, b.sh should notify me about the same. Thanks in Advance (4 Replies)
Discussion started by: rajusa10
4 Replies
Login or Register to Ask a Question