Shell practice: mysqlindex file check mechanism

Source: Internet
Author: User
Shell practice: mysqlindex file check mechanism 01! Binsh02def_check_index () 03 {04codebyscpman05http: wwwscpmancom06mail: freeddser @ gmailcom07 requirement: 08091 practice through showmasterlog shell: mysql index file check mechanism
01 #! /Bin/sh02def_check_index () 03 {04 # code by scpman05 # http://www.scpman.com06#mail:freeddser@gmail.com07# Requirement: 08 #09 #1. use show master logs; to list binlog file sequences. if the sequence is incorrect, or record repeated alerts and send email alerts. 10 #2. view the index file in the mysql Directory. if the order is incorrect, or record repeated alarms 11 #12 # implement 13 # send alarm function 14def_send_mail () 15 {16 msgip = "10.0.7.44" # syslog server 17ser_IP = 'cat/etc/rc. conf | grep-E "ifconfig _ [em1 | bce1]" | awk '{print "IP: "$2} '| sed-n 1 P' # ip18 on the local machine # echo $1 function receives the first value 19if [-n" $1 "] & ['echo "$1" | grep-c 'chongfu'-gt 0] # determines whether $1 is present, check whether the chongfu character is greater than 020then21echo/usr/bin/logger-p local1.info-h $ msgip "the services: $ IP mysql in Dex file $1 "# an error occurs if it is greater than 0, you need to trigger the alarm 22exit23elif [-n "$1"] & ['echo "$1" | grep-c 'luanle'-gt 0] # determine whether $1 is present, check whether the character luanle is greater than 024then25echo/usr/bin/logger-p local1.info-h $ msgip "the services: $ IP mysql index file $1 "# if the value is greater than 0, an error occurs. Therefore, you must generate an alarm: 26exit27else28echo ok29fi30} 31 #1. check whether the index is duplicated. 32def_index_is_one () 33 {34if [-n "$1"] 35then36static_index = $ 137def_send_mail 'awk' {a [$1] ++} END {for (j in a) print j, A [j]} '$ static_index | awk-v flag = "$ static_index"' {if ($2> 1) print "chongfu -->" $0} ''38else39echo 'Def _ index_is_one $1 is null! Exit '40exit41fi42} 43 # check whether the content sequence of the index file under the mysql directory is normal 44def_static_index_shunxu () 45 {46 bzfile = '/usr/dlm_db/mysql/zqtx-bin.index' 47current _ line = 'cat $ {bzfile} | head-n 1 | sed-e "s #. /zqtx-bin. # g "'48for I in 'cat $ {bzfile} '49do50if ['echo $ I | sed-e" s #. /zqtx-bin. # g "'-lt" $ current_line "] 51then52def_send_mail" luanle :$ {bzfile }_$ {current_line} "53exit54fi55current_line = 'echo $ I | sed-e" s #. /zqtx-bin. # g "'56done57} 58 # check whether the index file sequence of show master logs in mysql is normal. 59def_masterlog_index_shunxu () 60 {61 mysql-uroot-p123456-s-e "show master logs;" | awk '{print $1}' | sed-e "s/zqtx-bin. // g ">/usr/dlm_db/mysql/flag_index62bzfile =/usr/dlm_db/mysql/flag_index63current_line = 'cat $ {bzfile} | head-n 1 '64for I in 'cat $ {bzfile} '65do66if ["$ I"-lt "$ current_line"] 67then68def_send_mail "luanle: master_logs _ $ {I} "placement =" $ I "72done73} 74def_index_is_one '/usr/dlm_db/mysql/zqtx-bin.index '75def _ one'/usr/dlm_db/mysql/flag_index '78} 79def_check_index

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.