Shell script to restart MySQL server if it is killed or not working

in Categories Monitoring last updated April 10, 2008


Share this on:

7 comment

  1. #!/bin/bash
    email=’johndoe@doe.com’
    sub_mysql=’mysql proses down and up’
    MYSQL_START=’/etc/init.d/mysql start’
    MYSQL=’mysql’
    PGREP=’/usr/bin/pgrep’
    #check pid
    $PGREP $MYSQL
    if [ $? -ne 0 ]; then
    $MYSQL_START | mail -s “$sub_mysql” $email
    fi

  2. Would work better if it check that it could accept commands.

    Something Like….

    mysql -Dmysql -e “SELECT 1;”

    ;)

  3. Hello

    Thanks for this nice script.
    I’m quite new at server administration, and have 2 questions about your script :
    1- What do you mean by :
    # path to mail program
    MAILCMD=”$(which mail)”
    # path mysqladmin
    MADMIN=”$(which mysqladmin)”

    Do I need to enter the path of both mail and mysql servers ?

    2- If I enter wrong information for the password (and I leave the default intel as question 1), it works …
    So are login and pawd required ?
    Do it works only I 1- is correctly filled ?

    (I’m working with a ovh release 2 (gentoo))

    Thanks
    Ed

    Have a question? Post it on our forum!