怎么实现每隔30秒循环收集MYSQL备库状态信息的SHELL脚本
slave_status.sh
x=0
while [ $x -lt 50 ]
do
mysql -u root -proot_tcl -e "show slave status \G" >> slave_status.txt
x=`expr $x + 1`
echo '#########################################################################' >> slave_status.txt
sleep 10
done
下面的脚本是使用 expect 在脚本中自动输入密码
x=0
while [ $x -lt 50 ]
do
expect <<EOF
spawn mysql -u root -p -e "show slave status\\\G"
expect "*password:"
send "Ky_qmt@0414\r"
expect eof
EOF
x=`expr $x + 1`
echo '#########################################################################' >> slave_status.txt
sleep 10
done