Shell practice: mysqlindex File Check Mechanism

Source: Internet
Author: User
Tags mysql index
Welcome to the Linux community forum and interact with 2 million technical staff. This article will focus on the mysqlindex File Check Mechanism in shell practice. Please first read the code: 01 #! Binsh02def_check_index () 03 {04 # codebyscpman05 #. scpman.06 # mail: freeddser@gmail.com07 # requirement: 08 #

Welcome to the Linux community forum and interact with 2 million technical staff> This article focuses on the mysql index file check mechanism in shell practice. Please first read the code: 01 #! /Bin/sh 02def_check_index () 03 {04 # code by scpman 05 # http: //. scpman. 06 # mail: freeddser@gmail.com 07 # requirement: 08 #

Welcome to the Linux community forum and interact with 2 million technicians>

This article focuses on the mysql index file check mechanism in shell practice. Read the code first:

01 #! /Bin/sh

02def_check_index ()

03 {

04 # code by scpman

05 # http: //. scpman.

06 # mail: freeddser@gmail.com

07 # requirements:

08 #

09 #1. Use show master logs; To list binlog file sequences. If the sequence is incorrect, or record repeated alarms and send email alerts.

10 #2. view the index file in the mysql directory. If the order is incorrect, or record duplicate alerts

11 #

12 # implementation

13 # alarm sending 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' # local ip Address

18 # The first value received by the echo $1 Function

19if [-n "$1"] & ['echo "$1" | grep-c 'chongfu'-gt 0] # determine whether $1 is present, check whether the chongfu character is greater than 0.

20 then

21 echo/usr/bin/logger-p local1.info-h $ msgip "the services: $ IP mysql index file $1" # If the value is greater than 0, an alarm is triggered.

22 exit

23 elif [-n "$1"] & ['echo "$1" | grep-c 'luanle'-gt 0] # determine whether $1 is present, check whether the character luanle is greater than 0.

24 then

25 echo/usr/bin/logger-p local1.info-h $ msgip "the services: $ IP mysql index file $1" # If the value is greater than 0, an alarm is triggered.

26 exit

27 else

28 echo OK

29fi

30}

31 #1. Check whether the index is duplicated

32def_index_is_one ()

33 {

34if [-n "$1"]

35 then

36static_index = $1

37def_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 }''

38 else

39 echo 'def _ index_is_one $1 is null! Exit'

40 exit

41fi

42}

43 # Check whether the order of index files 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 }'

49do

50if ['echo $ I | sed-e "s #./zqtx-bin. # g" '-lt "$ current_line"]

51 then

52def_send_mail "luanle :$ {bzfile }_$ {current_line }"

53 exit

54fi

55current_line = 'echo $ I | sed-e "s #./zqtx-bin. # g "'

56 done

57}

58 # Check whether the content sequence of the show master logs index file 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_index

62 bzfile =/usr/dlm_db/mysql/flag_index

63current_line = 'cat $ {bzfile} | head-n 1'

64for I in 'cat $ {bzfile }'

65do

66if ["$ I"-lt "$ current_line"]

67 then

68def_send_mail "luanle: master_logs _ $ {I }"

69 exit

70fi

71current_line = "$ I"

72 done

73}

74def_index_is_one '/usr/dlm_db/mysql/zqtx-bin.index'

75def_static_index_shunxu

76def_masterlog_index_shunxu

77def_index_is_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.