处理Mysql监控脚本取值异常问题
执行用户:mysql
脚本内容:
#! /bin/sh
OSCheckCentOS8=`cat /etc/redhat-release 2>/dev/null |awk '{print $4}' |awk -F"." '{print $1}'`
OSCheckSuse=`cat /etc/issue |awk NR==2 |awk '{print $3}'`
OSCheckKylinV10=`cat /etc/os-release |sed -n '5p' |awk -F '[ "]' '{print $2}'`
MASTER=`ps -ef |grep -v grep |grep -i masterha_manager |wc -l`
ISHA=`cat /mysql/scripts/zabbix/scripts/zbx_mysql_status.py |grep -w "isHA= [0-9]" |awk '{print $NF}'`
ISHA0=0
ISHA1=1
CRONTAB=`crontab -l |grep zbx_mysql_status.py |wc -l`
PYTHON3=`which python3`
nowtime=`date+%Y%m%d%H%M`
logfile=/tmp/zbx_mysql_status.${nowtime}_mysql.log
###################################### isHA Control ############################################
if [ $OSCheckSuse == SUSE ];then
echo "$OSCheckSuse"
echo "$OSCheckSuse" >>logfile
elif [ X$OSCheckKylinV10 == Xkylin ] || [ XOSCheckCentOS8 == X8 ];then
seeds=`cat /mysqldata/myinst1/etc/my.cnf |grep -i loose-group_replication_group_seeds |wc -l`
if [ "$seeds" -eq 1 ];then
sed -i "s/"$ISHA"/"$ISHA1"/g" /mysql/scripts/zabbix/scripts/zbx_mysql_status.py
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}"
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}" >>logfile
elif [ "$seeds" -eq 0 ];then
lscpu=`lscpu |grep -i "Hypervisor vendor:" |awk '{print $3}'`
if [ "$lscpu" == VMware] || [ "$lscpu" == KVM];then
if [ "$MASTER" -eq 0 ];then
sed -i "s/"$ISHA"/"$ISHA0"/g" /mysql/scripts/zabbix/scripts/zbx_mysql_status.py
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}"
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}" >>logfile
else
echo "(virtual machine)Please Database teacher verfy: Virtual machine exist masterha_manager processes"
exit 1
fi
fi
else
if [ "$MASTER" -eq 0 ];then
sed -i "s/"$ISHA"/"$ISHA0"/g" /mysql/scripts/zabbix/scripts/zbx_mysql_status.py
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}"
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}" >>logfile
else
sed -i "s/"$ISHA"/"$ISHA1"/g" /mysql/scripts/zabbix/scripts/zbx_mysql_status.py
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}"
echo "${nowtime} (MGR framework)Master number of processes(0:is not master node;1: is masternode;):${ISHA}" >>logfile
fi
fi
else
echo "Error!os is not supported!,exit"
echo "Error!os is not supported!,exit" >>logfile
exit 1
fi
###################################### Check Crontab ############################################
if [ $CRONTAB -eq 0 ];then
echo "${nowtime} Crontab Check(0: Not configured crontab;1: configured crontab;)${CRONTAB}"
echo "${nowtime} Crontab Check(0: Not configured crontab;1: configured crontab;)${CRONTAB}" >>logfile
else
crontab -l
crontab -l >>logfile
###################################### Execute Crontab ############################################
MYSQLVALUE=`crontab -l |grep zbx_mysql_status.py |awk -F'[*]+'` '{print $NF}'
touch /mysql/scripts/zabbix/scripts/zbx_mysql_status.sh
echo $MYSQLVALUE > /mysql/scripts/zabbix/scripts/zbx_mysql_status.sh
sh /mysql/scripts/zabbix/scripts/zbx_mysql_status.sh && echo "${nowtime} Script Execution Result(NO: On failure,YES Execute succcessfuly;)YES" || echo "${nowtime} Script Execution Result(NO: On failure,YES Execute succcessfuly;)NO"
sh /mysql/scripts/zabbix/scripts/zbx_mysql_status.sh && echo "${nowtime} Script Execution Result(NO: On failure,YES Execute succcessfuly;)YES" || echo "${nowtime} Script Execution Result(NO: On failure,YES Execute succcessfuly;)NO" >> logfile
if