Skip to content

Instantly share code, notes, and snippets.

@manickamk
Created March 28, 2018 17:37
Show Gist options
  • Save manickamk/c4415c48b5b6689811e9db258827d487 to your computer and use it in GitHub Desktop.
Save manickamk/c4415c48b5b6689811e9db258827d487 to your computer and use it in GitHub Desktop.
# cat /root/service.sh
################################################################
#!/bin/bash
###edit the following
service=searchd
email=XXXXX@XXXXXX.com
###stop editing
host=`hostname -f`
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
date +\%Y\-%m\-%d\ %H\:%M\:%S
echo "$service is running"
else
/etc/init.d/rc.searchd start
if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 ))
then
subject="$service at $host has been started"
echo "$service at $host wasn't running and has been started" | mail -s "$subject" $email
else
subject="$service at $host is not running"
echo "$service at $host is stopped and cannot be started!!!" | mail -s "$subject" $email
fi
fi
[root@host01 ~]#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment