linux使用shell脚本检测主从服务(内部案例,仅供参考)

时间:2022-12-04 15:33:57
#!/bin/bash
user=***
password=***
echo -e "please inpute slave portarl ip:"
read host


cd `dirname $0`
mysql -u$user -p$password -h$host -e "show slave status\G;" | grep -i running >slave.log
#grep -i, --ignore-case        
#            忽略大小写,包含要搜寻的样式及被搜寻的档案。
if [ `cat slave.log | grep -i io | awk '{print $2}'` = Yes ]
  then
     echo "slave IO process is OK"
else
     echo "slave IO process is error"
fi
if [ `cat slave.log | grep -i sql | awk '{print $2}'` = Yes ]
  then
     echo "slave SQL process is OK"
else
     echo "slave SQL process is error"
fi
rm -rf slave_status