【mysql】两个实例参数对比脚本
时间:2015-01-11 11:01:22 作者:beebol 标签: mysqladmin 分类: mysql
share一下这个脚本,功能主要是通过mysqladmin var读取所有参数配置项,然后与另一个实例进行比较。有时候在排查问题时有用。
#!/bin/bash # #Created by beebol #URL:http://www.itopers.com # BASEDIR="/home/xxx/script" LIST="${BASEDIR}/iplist.txt" TMPDIR="${BASEDIR}/log" cat $LIST |egrep -v "^#|^$"|awk -F"[:|\t| ]+" '{print $1"\t"$2"\t"$3"\t"$4"\t"$5}' |while read ip1 port1 ip2 port2 var do ssh $ip1 "mysqladmin -uroot -P${port1} var " </dev/null >${TMPDIR}/${ip1}.txt ssh $ip2 "mysqladmin -uroot -P${port2} var " </dev/null >${TMPDIR}/${ip2}.txt if [ ! -z "${var}" ];then value1=$(egrep -v '^\+|Variable_name|^$' ${TMPDIR}/${ip1}.txt |awk -F"[|| ]+" '$2=="'${var}'" {print $3}') value2=$(egrep -v '^\+|Variable_name|^$' ${TMPDIR}/${ip2}.txt |awk -F"[|| ]+" '$2=="'${var}'" {print $3}') if [ "${value1}" = "${value2}" ];then echo -e "${ip1} and ${ip2} 's ${var} are the same.[\033[32mOK\033[0m]" else echo -e "${ip1} and ${ip2} 's ${var} are different.[\033[5m\033[31mError\033[0m]" fi else egrep -v '^\+|Variable_name|^$' ${TMPDIR}/${ip1}.txt |awk -F"[|| ]+" '{print $2"\t"$3}'|while read key value1 do value2=$(egrep -v '^\+|Variable_name|^$' ${TMPDIR}/${ip2}.txt |awk -F"[|| ]+" '$2=="'${key}'" {print $3}') if [ "${value1}" = "${value2}" ];then echo -e "${ip1} and ${ip2} 's ${key} are the same.[\033[32mOK\033[0m]" else echo -e "${ip1} and ${ip2} 's ${key} are different.[\033[5m\033[31mError\033[0m]" fi done fi doneexit 0 exit 0
配置文件:
#ip:port ip2:port2 variable2.2.2.2:3306 1.1.1.1:3306 tmpdir 2.2.2.2:3306 1.1.1.1:3306 tmpdir
如果variable为空,者检查两个实例所有参数值。