Service script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Service script
# 1  
Old 05-13-2013
Service script

Hi Folks,

I need to find out and trigger if the service is running to OK and not running to NOTOK. I use the below script but, its not the precise output. Anything missed out in the script:
Code:
if chkconfig --list | grep -i sendmail
then
        echo " The sendmail service is not running : STATUS--> NOOK"
        echo
else
        echo " The sendmail service is running : STATUS--> OK"
        echo
fi


Last edited by Scott; 05-13-2013 at 04:06 AM.. Reason: Code tags
# 2  
Old 05-13-2013
Use the service command itself to check if a service is running.

Code:
if service sendmail status >/dev/null; then
  echo OK
else
  echo NOK
fi

# 3  
Old 05-13-2013
try changing if loop to check for count of sendmail if 0 found if loop will result in false else true
Code:
 
if [ `chkconfig --list | grep -c -i sendmail` ]

# 4  
Old 05-14-2013
Thanks Vidya and Scott,

Actually, if the sendmail if on -> its should flag as OK
and if sendmail if off -> it should flag as NOTOK as per the command chkconfiig -list | grep -i sendmail

Code:
  chkconfig --list | grep -i sendmail
sendmail        0: off   1: off   2: on    3: on    4 :on    5: on    6: off


Last edited by Scott; 05-21-2013 at 12:53 AM.. Reason: Code tags
# 5  
Old 05-14-2013
Code:
if chkconfig --list sendmail | grep '[345]:off'
then
  echo " sendmail not configured for autostart : STATUS--> NOOK"
  echo
else
  echo " sendmail configured for autostart : STATUS--> OK"
  echo
fi

# 6  
Old 05-21-2013
Thanks Madein. Your script works perfectly. also one more thing.
Code:
chkconfig --list | grep -i telnet
    ekrb5-telnet:      off
    krb5-telnet:       off
    telnet:            off

How can I make sure like the previous script.

Last edited by Scott; 05-21-2013 at 12:54 AM.. Reason: Code tags
# 7  
Old 05-23-2013
Make sure what?
All 3 services are on/off? Any of these services are on/off?
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script to automate a service message

Hi I am trying to figure out, on how to automate whether in a simple script or using awk/sed/grep commands to automate a "service.message" file which has tag separated message stating as; "There is currently no outage or system is unavailable for duration of change....", therefore, when... (14 Replies)
Discussion started by: Gamma
14 Replies

2. UNIX for Beginners Questions & Answers

Run one service after another service has finished - systemd

Hi all I would like to know how to run task2.service after task1.service has finished. task1.service has a timer (task1.timer), that makes it run every 5 minutes OnCalendar=*:0/5task2.service is basically a script, that has to work on the files created after task1 has finished. This is what I... (2 Replies)
Discussion started by: guilliber
2 Replies

3. 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

4. Shell Programming and Scripting

script for monitoring service

Hi, I am new to shell programming, I would like to write a script which will monitor sendmail service in linux, and if service goes down it will send the mail can you please suggest me how to monitor the service? Regards, Manoj (2 Replies)
Discussion started by: manoj.solaris
2 Replies

5. UNIX for Dummies Questions & Answers

Making a Script to Start as a Service

Hi, I have a shell script t1.sh. on my solaris box. So, what are the steps required to make this script run as a Service, when the system re-starts. (for ex:- at run level 3). I know that I should use the rc.d folders. But I don't know the exact steps. Kindly explain, Thanks in... (3 Replies)
Discussion started by: S.Vishwanath
3 Replies

6. Shell Programming and Scripting

Getting a script to find another script via lookup service

Hi, I'm trying to write a basic script which will measure throughput at a node on a network, and pass the results on to a manager script (running on another node on the same network). I presume that I need to use some sort of naming service, so that the manager can publish its location. From what I... (2 Replies)
Discussion started by: zeppelin147
2 Replies
Login or Register to Ask a Question