分类: Mysql/postgreSQL
2008-06-27 17:56:33
#!/bin/sh
#
# Created by david yeung
#
# To determine whether slave is running or not.
echo "Enter your Username"
read USERNAME
echo "Enter your password"
stty -echo
read PASSWD
stty echo
cd /usr/local/mysql/bin
RESULT=`./mysql -u$USERNAME -p$PASSWD -e 'show status like "Slave_running"' -ss | awk '{print $2}'`
if [ "$RESULT" == 'ON' ]
then
echo "Slave is running!" > /var/log/mysql_slave.log
else
echo "Slave is not running!"> /var/log/mysql_slave.log
fi
#!/bin/sh
#
# Created by david yeung
#
# To determine whether slave is running or not.
echo "Enter your Username"
read USERNAME
echo "Enter your password"
stty -echo
read PASSWD
stty echo
cd /usr/local/mysql/bin
RESULT=`./mysql -u$USERNAME -p$PASSWD -e 'show slave status\G' -ss| awk '{print $2}' | head -n 13 | tail -n2`
if [ "$RESULT" == 'Yes Yes' ]
then
echo "Slave is running!" > /var/log/mysql_slave.log
else
echo "Slave is not running!"> /var/log/mysql_slave.log
fi
3、测试一下
[root@localhost ~]# ./slave_is_running
Enter your Username
root
Enter your password
[root@localhost ~]# cat /var/log/mysql_slave.log
Slave is running!
我停掉SLAVE。
[root@localhost ~]# cat /var/log/mysql_slave.log
Slave is not running!