-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql_slave_status-2.sh
More file actions
53 lines (48 loc) · 1.09 KB
/
mysql_slave_status-2.sh
File metadata and controls
53 lines (48 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
USER=root
PSD=123
SOCK=/data/3307/mysql.sock
CMD="mysql -u$USER -p$PSD -S $SOCK"
errno=(1158 1159 1008 1007 1062)
check_status() {
if [ "${status[0]}" == "Yes" -a "${status[1]}" == "Yes" -a "${status[2]}" == "0" ]
then
echo "mysql is ok"
sta=0
return $sta
else
return 2
fi
}
check_error() {
check_status
if [ $? -ne 0 ]
then
for((i=0;i<${#errno[*]};i++))
do
if [ "${errno[i]}" == "${status[3]}" ]
then
$CMD -e "stop slave;set global sql_slave_skip_counter = 2;start slave"
fi
done
fi
}
check_again() {
status=($($CMD -e "show slave status\G" | egrep "*_Running|Seconds_Behind_Master|Last_SQL_Errno" | awk '{print $NF}'))
ckeck_status &>/dev/null
if [ $? -ne 0 ]
then
echo "mysql slave is not ok `date +%F`" | tee /tmp/slave.log
mail -s "mysql slave is not ok `date +%F`" liteng51@163.com </tmp/slave.log
fi
}
main() {
while true
do
status=($($CMD -e "show slave status\G" | egrep "*_Running|Seconds_Behind_Master|Last_SQL_Errno" | awk '{print $2}'))
check_error
check_again
sleep 5
done
}
main