The following describes how to organize scripts on the Internet and make improvements based on actual conditions. #! Binshusagequot; $ 0-hlocalhost-uroot-pxxxx-P3306quot; dbhostquot
The following describes how to organize scripts on the Internet and make improvements based on actual conditions. #! /Bin/shusage = quot; $0-hlocalhost-uroot-pxxxx-P3306quot; dbhost = quot
The following describes how to organize scripts on the Internet and make improvements based on actual conditions.
#! /Bin/sh
Usage = "$0-hlocalhost-uroot-pxxxx-P3306"
Dbhost = "localhost"
Dbuser = ""
Dbpass = ""
Dbport = 3306
For varin in $ *; do
If [$ {varin: 0: 2} = '-H']; then
Dbhost =$ {varin: 2}
Fi
If [$ {varin: 0: 2} = '-U']; then
Dbuser =$ {varin: 2}
Fi
If [$ {varin: 0: 2} = '-p']; then
Dbpass =$ {varin: 2}
Fi
If [$ {varin: 0: 2} = '-p']; then
Dbport =$ {varin: 2}
Fi
Done
Echo $ dbhost
Echo $ dbuser
Echo $ dbpass
Echo $ dbport
Now = 'date + "% Y % m % d % H % M % S "'
Datelog = 'date + "% Y-% m-% d % H: % M: % S "'
StatFile = "./slave_status. $ now"
Checklogfile = "/var/log/mysql_slavecheck.log"
Echo "show slave status \ G" |/usr/local/mysql/bin/mysql-u $ dbuser-p $ dbpass-h $ dbhost-P $ dbport> $ StatFile
# Get io_thread, SQL _thread, last_errno status
# **************************** 1. row ***************************
# Slave_IO_State: Connecting to master
# Master_Host: 192.168.213.5
# Master_User: synuser
# Master_Port: 3306
# Connect_Retry: 60
# Master_Log_File: mysql-bin.000019
# Read_Master_Log_Pos: 366270403
# Relay_Log_File: Test-Web1-relay-bin.003133
# Relay_Log_Pos: 98
# Relay_Master_Log_File: mysql-bin.000019
# Slave_IO_Running: No
# Slave_ SQL _Running: Yes
# Replicate_Do_DB:
# Replicate_Ignore_DB:
# Replicate_Do_Table:
# Replicate_Ignore_Table:
# Replicate_Wild_Do_Table:
# Replicate_Wild_Ignore_Table:
# Last_Errno: 0
# Last_Error:
# Skip_Counter: 0
# Exec_Master_Log_Pos: 98
# Relay_Log_Space: 98
# Until_Condition: None
# Until_Log_File:
# Until_Log_Pos: 0
# Master_SSL_Allowed: No
# Master_SSL_CA_File:
# Master_SSL_CA_Path:
# Master_SSL_Cert:
# Master_SSL_Cipher:
# Master_SSL_Key:
# Seconds_Behind_Master: NULL
IOSTAT = 'grep "Slave_IO_Running" $ StatFile | awk '{print $2 }''
SQLSTAT = 'grep "Slave_ SQL _Running" $ StatFile | awk '{print $2 }''
Last_Errno = 'grep "Last_Errno" $ StatFile | awk '{print $2 }''
Last_Error = 'grep "Last_Error" $ StatFile | awk '{print $2 }''
Behind_Master = 'grep "Seconds_Behind_Master" $ StatFile | awk '{print $2 }''
If [$ IOSTAT = 'no'] | [$ SQLSTAT = 'no']; then
Echo "Server $ dbhost: $ dbport Slave is down, Check Time is: $ datelog"> $ checklogfile
If [$ Behind_Master = 'null']; then
Echo "Server $ dbhost: $ dbport Slave not support slave-master, Check Time is: $ datelog" >>$ checklogfile
Else
Echo "> Last_ErrNo: $ Last_Errno"> $ checklogfile
Echo "> Last_Error: $ Last_Error"> $ checklogfile
Echo "> slave is behind master $ Behind seconds! ">>> $ Checklogfile
Fi
Fi
/Bin/rm-rf $ StatFile
,