Written question Shell

Source: Internet
Author: User
Tags mysql view egrep

Enterprise Practice question 1: (Production actual case): monitor MySQL master-slave synchronization is abnormal, if abnormal, send sms or mail to the administrator. Note: If there is no master-slave synchronization environment, you can use the following text in the file to read to simulate:
Phase 1: Develop a daemon script to detect every 30 seconds.
Phase 2: If the following error number (1158,1159,1008,1007,1062) is present in the synchronization, the error is skipped.

Phase 3: Use array technology to implement the above script (get master-slave judgment and error number section)

MySQL View status statement

Mysql>show slave Status\g

1. Row ***************************
Slave_io_state:waiting for Master to send event
master_host:10.0.0.42
Master_user:backup
master_port:3306
Connect_retry:60
master_log_file:mysql-bin.000001
read_master_log_pos:538
relay_log_file:mysql-relay-bin.000002
relay_log_pos:701
relay_master_log_file:mysql-bin.000001
Slave_io_running:yes
Slave_sql_running:yes


Use the MYSQLCMD2 command to filter after statements:

Yes
Yes
0
0
It

#!/bin/Bashport=3306Error=(1158 1159 1008 1007 1062) MysqlCmd1= mysql-uroot-p192.168.51.9-EMYSQLCMD2= mysql-uroot-p192.168.51.9-E"Show Slave Status\g"|Egrep "_running| last_errno| Behind_master"|awk '{print $NF}'functionIs_run () {[' Lsof-I: $port |WC-L '-lt2]&&{ Echo"MySQL is stop"Exit1 }}functionMysql_status () {array=(' $MysqlCmd 2 ')}functionJudge_error () { forIinch${error[*]} Do   if["${array[2]}"=="$i"]; Then$MYSQLCMD 1"stop Slave; SET GLOBAL sql_slave_skip_counter = 1;start SLAVE;"  Else   Echo "MySQL is failed,error ID is ${array[2]}"  fi Done}judge_status () {mysql_statusEcho${array[*]}if["${array[0]}"=="Yes"-A"${array[1]}"=="Yes"-A"${array[3]}"=="0"]; Then    Echo "Mysql slave is ok"ElseJudge_error ${array[2]}fi}functionMain () { while true  DoIs_run Judge_statusSleep  -  Done}main
View Code
1#!/bin/Bash2 3port=33064Error= (1158 1159 1008 1007 1062)5Mysqlcmd1= mysql-uroot-p192.168.51.9-e6Mysqlcmd2= mysql-uroot-p192.168.51.9-E"Show Slave Status\g"|Egrep "_running| last_errno| Behind_master"|awk '{print $NF}'7 8 functionIs_run () {9[' Lsof-i: $port |WC-L '-lt2]&&{Ten  Echo"MySQL is stop" OneExit1 A  } - } -  the  - functionMysql_status () { -array=(' $MYSQLCMD 2 ') -  } +  -  + functionJudge_error () { A  forIinch${error[*]} at  Do  -   if["${array[2]}"=="$i"]; Then -$MYSQLCMD 1"stop Slave; SET GLOBAL sql_slave_skip_counter = 1;start SLAVE;" -   Else -    Echo "MySQL is failed,error ID is ${array[2]}" -   fi in  Done - } to  + Judge_status () { - Mysql_status the Echo${array[*]} * if["${array[0]}"=="Yes"-A"${array[1]}"=="Yes"-A"${array[3]}"=="0"]; Then $     Echo "Mysql slave is ok"Panax Notoginseng Else -Judge_error ${array[2]} the fi + } A  the  + functionMain () { -  while true $   Do $ Is_run - Judge_status -    Sleep  - the   Done - }Wuyi  the  -Main

#!/bin/Bashport=3306Error=(1158 1159 1008 1007 1062) MysqlCmd1= mysql-uroot-p192.168.51.9-EMYSQLCMD2= mysql-uroot-p192.168.51.9-E"Show Slave Status\g"|Egrep "_running| last_errno| Behind_master"|awk '{print $NF}'functionIs_run () {[' Lsof-I: $port |WC-L '-lt2]&&{ Echo"MySQL is stop"Exit1 }}functionMysql_status () {array=(' $MysqlCmd 2 ')}functionJudge_error () { forIinch${error[*]} Do   if["${array[2]}"=="$i"]; Then$MYSQLCMD 1"stop Slave; SET GLOBAL sql_slave_skip_counter = 1;start SLAVE;"  Else   Echo "MySQL is failed,error ID is ${array[2]}"  fi Done}judge_status () {mysql_statusEcho${array[*]}if["${array[0]}"=="Yes"-A"${array[1]}"=="Yes"-A"${array[3]}"=="0"]; Then    Echo "Mysql slave is ok"ElseJudge_error ${array[2]}fi}functionMain () { while true  DoIs_run Judge_statusSleep  -  Done}main

Enterprise Practice Question 2:
Use the For loop in the/oldboy directory to create 10 HTML files in bulk by using a random lowercase 10-letter plus a fixed string oldboy, for example:

Coaolvajcq_oldboy.html qnvuxvicni_oldboy.html

#!/bin/ For  ((i=1; i<=, i++ ))doa= 'tr' A- z "  Head Ten ' _oldboy,html   Touch $dir/$a  Done

#tr-DC means to extract and delete characters from A to Z in a string

Written question Shell

Related Article

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.