Enterprise Real Shell interview questions, a challenge to put!
Statement: If there is a similar, purely plagiarism
1. Develop a daemon script that executes every 30 seconds to check MySQL master-slave synchronization
[email protected] scripts]# cat check_mysql_slave_status.sh
#!/bin/bash
# date 2016-1-5
# author Tom
# mail [email protected]
# function Check_mysql_slave_status
# version 4.1.2
# # # #do It behind start mysql####
#grep "slave-skip-errors ="/data/3307/my.cnf |awk-f "[]" ' {print $} ' |sed-i ' s #.* #1158 \,1159\,1007\,1008\,1062#g "
# # # #define $IP $DATE # # #
ip=$ (ifconfig eth0|awk ' {if (nr==2) print $} ' |awk -F "[:]+" ' {print $4} ')
date=$ (DATE "+%f%h:%m:%s")
# # # #check mysql_slave_status####
mysql_slave_status=$ ( Mysql-uroot-p123456-s/data/3307/mysql.sock-e "show slave Status\g" |sed-n ' 12,13p ' |awk-f ":" ' {print $} ' |uniq-c) if ["$mysql _slave_status" = = " 2 Yes"]
then
echo "MySQL slave is Runi ng OK "
Else
echo" ##################### $DATE $IP ########################## ">>~/oldboy.txt
echo "Warn:mysql slave is not runing" >>~/oldboy.txt && mail-s "Check_mysql_slave_status" [email protected] <~/ Oldboy.txt
Fi
[email protected] scripts]# cat do.sh
#!/bin/bash
# date 2016-1-5
# author Tom
# mail [email protected]
# function do Check_mysql_slave_status
# version 4.1.2
While True
Do
/bin/sh/server/scripts/check_mysql_slave_status.sh
Sleep 30
Done
2. Randomly generate 10-letter plus fixed-field 10 HTML files with a for loop
[email protected] scripts]# cat touch_html.sh
#!/bin/bash
# date 2016-1-5
# author Tom
# mail [email protected]
# function Touch html
# version 4.1.2
a=$ (head-c 500/dev/urandom |tr-dc a-z|head-c 10)
B=_oldboy.html
CD ~/oldboy
For i in {1..10}
Do
a=$ (head-c 500/dev/urandom |tr-dc a-z|head-c 10)
Touch $A $b-$i
MV $A $b-$i $A $b
Done
3, replace all the Oldboy in the above file with Oldgirl, and HTML for HTML (with for loop)
Act 1):
[email protected] scripts]# cat change_touch_html.sh
#!/bin/bash
# date 2016-1-5
# author Tom
# mail [email protected]
# function Change Touch html
# version 4.1.2
For n in ' ls ~/oldboy '
Do
echo $n |sed "s#oldboy#oldgirl#g" |sed "S#html#html#g"
Done
Add:
Viewing the execution of timed tasks [email protected] scripts]# tail-f/var/log/cron
This article is from the "it--Brother" blog, please make sure to keep this source http://402753795.blog.51cto.com/10788998/1732305
All those years we've been together. Shell face questions (I.)