0 like 0 dislike
71 views

Please log in or register to answer this question.

1 Answer

0 like 0 dislike
answered by (4k points)  
##list your services you want to check
##you can add as many as you like
SERVICES=('MySQL')

#### DO NOT CHANGE anything BELOW ####


 for i in "${SERVICES[@]}"
  do
    ###IF SERVICE IS NOT RUNNING####

if [[  "$(service $i status)"=~"not"  ]]

    then
       ##TRY TO RESTART THAT SERVICE###
mv /var/lib/mysql/ib_logfile* /tmp/
    service $i start

        ##IF RESTART WORKED###
if [[  "$(service $i status)"=~"$i running"  ]]

    then
        ##SEND AN EMAIL###
    MESSAGE="$(tail -10 /var/lib/mysql/vps.publishman.com.err)"
    SUBJECT="$i down -but restarted-  on $(hostname) $(date) "
    echo "   $i  $MESSAGE "  | mail -s "$SUBJECT" "$EMAIL"
       else

        ##IF RESTART DID NOT WORK SEND A DIFFERENT EMAIL###
    MESSAGE="$(tail -10 /var/lib/mysql/vps.publishman.com.err)"
    SUBJECT="$i down on $(hostname) $(date) "
    echo "   $i  $MESSAGE  . I tried to restart but it did not work"  | mail -s "$SUBJECT" "$EMAIL"

       fi
    fi



                  ################### DOWN APACHE server######################
#!/bin/bash
#ver. 2

##this script will check whatever services
##you want to keep an eye on
##if that service is not running
##it will (try to) start the service and send
##an email to you

##set your email address
EMAILA="nijamutheen060@gmail.com"

##list your services you want to check
##you can add as many as you like
SERVICESA=('httpd')

#### DO NOT CHANGE anything BELOW ####


 for a in "${SERVICESA[@]}"
  do
    ###IF SERVICE IS NOT RUNNING####

if [[  "$(service $a status)"=~"$a is stopped"  ]]

    then
       ##TRY TO RESTART THAT SERVICE###
    service $a start

        ##IF RESTART WORKED###
if [[  "$(service $a status)"=~"is running"  ]]

    then
        ##SEND AN EMAIL###
    MESSAGEA="$(tail -10 /var/log/apache2/error_log)"
    SUBJECTA="$a down -but restarted-  on $(hostname) $(date) "
    echo "   $a  $MESSAGEA "  | mail -s "$SUBJECTA" "$EMAILA"
       else

        ##IF RESTART DID NOT WORK SEND A DIFFERENT EMAIL###
    MESSAGEA="$(tail -10 /var/log/apache2/error_log)"
    SUBJECTA="$a down on $(hostname) $(date) "
    echo "   $a  $MESSAGEA  . I tried to restart but it did not work"  | mail -s "$SUBJECTA" "$EMAILA"

       fi
    fi

  done
exit 0;

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked Mar 31, 2019 in MySQL Database Forum by nijamutheen j (13.4k points)  
0 like 0 dislike
1 answer
Welcome to PostgreSQL Database Discussion Forum where you can ask questions and receive answers from other members of the community. Can discuss here Oracle, Postgresql, mariadb , mySQL , AWS , Linux , MSSQL , MongoDB , Greenplum databases related queries ...etc.
...