Hello, please sign in or register
You are here: Home

Cron to check MySQL slave is up

#!/bin/bash
#
# Check to see if the slave server is running.
# -h    Slave Host
# -p    Slave password
# -u    Slave Username
#

# GET PARAMETERS (OVERIDING DEFAULTS)

while getopts  "h:u:p:H:U:P:" flag
do
  case "$flag" in
        h) echo "SLAVE_HOST: $OPTARG"
           SLAVEHOST=$OPTARG;;
        p) SLAVEPASS=$OPTARG;;
        u) SLAVEUSER=$OPTARG;;
        e) EMAIL=$OPTARG;;
  esac
done

# Check connection to slave

SLAVEVERSION=`mysql -h$SLAVEHOST -u$SLAVEUSER -p$SLAVEPASS --vertical -e "SELECT VERSION()"`
SLAVEVERSION=${SLAVEVERSION#*:}

if [ -z $SLAVEVERSION ]; then
    echo Could not connect to Slave
    exit 1
fi

## - GET INFORMATION FROM SLAVE

#SLAVEVERSION
echo "SLAVE_VERSION: $SLAVEVERSION"

#SLAVE is up?
SLAVE_UP=`mysql --vertical -h$SLAVEHOST -u$SLAVEUSER -p$SLAVEPASS -e "SHOW SLAVE STATUS" | grep "Slave_SQL_Running"`
SLAVE_UP=${SLAVE_UP#*:}
echo "SLAVE_UP: $SLAVE_UP"

if [ "$SLAVE_UP" != " Yes" ]; then
        echo "Status Down"
        exit 1;
else
        echo "Status Up"
        exit 0
fi

The above script can be run from within a crontab, something like this is useful to let you know by email that the slave is not running.

( ./mysql_check_slave_status.sh -hlocalhost -ppassword -uroot ) || echo "Slave is down" | mail -s "Slave is down" me@domain.com && echo "Message sent

Comments

guoyanying
But the replica watches sentry reebok shoes knew abercrombie and fitch uk his
Created 07/10/15
1015maoqiuyun
coach outlet online, http://www.coachoutletonline-store.us.com/
Created 15/10/15
clibin
Tyrion 5c cases watched her ray ban sunglasses read. His timber...
Created 18/04/16
chenyan
Bond grinned. pandora-bracciali.it "We bcbgmax.in.net only chaussure...
Created 15/06/16
chenyan
Bond grinned. pandora-bracciali.it "We bcbgmax.in.net only chaussure...
Created 15/06/16
michael kors factory outlet
adidas nmd pandora bracelet
Created 16/05/17
Title*
Comment

Prove you are not a robot

To prove you are not a robot, please type in the six character code you see in the picture below
Security confirmation codeI can't see this!
Contact
Name*
Email never shown*
Home Page

Author

Andrew Dodson
Since:Feb 2007

Comment | flag

Categories

Bookmark and Share