HOSTNAME=`hostname`

MYSQLPORT=`netstat -na | grep "LISTEN" | grep "3306"|cut -d: -f2|awk '{print $1}'`

MYSQLIP=`/sbin/ifconfig eth0 | grep "inet addr" | cut -d: -f2 | awk '{print $1}'`

STATUS=`/usr/local/mysql/bin/mysql -u root -pbxd123  -e "show slave status\G"| grep Running`

IO_env=`echo $STATUS | grep IO | awk -F " " '{print $2}'`

SQL_env=`echo $STATUS | grep IO | awk -F " " '{print $4}'`

IP=`/sbin/ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | awk '{ print $1}'`

if [ "$MYSQLPORT" -eq "3306" ]

then

   echo "mysql is running"

else

   echo "mysql is down"

if [ "$IO_env" == "Yes" ] && [ "$SQL_env" == "Yes" ]

then

   echo "Slave is running!"

else

   echo "$DATA" >> /var/log/check_mysql_slave.log

   echo "Slave is not running!" >> /var/log/check_mysql_slave.log