1. Interview questions: Use the For loop in the/tmp directory to create 10 HTML files in bulk, where each file needs to contain 10 random lowercase letters Plus fixed string template, such as the following
Aaesdffbnv_template.html
Method 1:
Cd/tmp
for ((i=0;i<; i++)); Do Touch 'echosed's/[^a-z]//g'cut1- ten' _template.html; Done
Method 2:
Cd/tmp
for in 'seq'; Do Touch + sed ' s/[^a-z]//g ' Cut 1-' _template.html; Done
2. Interview title: Batch renaming change the template in the file name above to Leon, and change the HTML to uppercase
Method 1:
Rename template.html Leon. HTML *.html
Method 2:
ls awk ' _ ' ' {print "MV" $ "$" _leon. HTML '}' | Bash
3, Interview questions: Batch 10 System account TEMPLATE01 to Template10 and set password (password is random number)
Method 1:
For i in ' seq-w ';d o useradd-m template$i;echo $RANDOM |md5sum | Cut-c 1-10 | Tee-a Passwd.log | Template$i;done
Method 2:
echo template{. Ten TR " " " \ n " sed ' s# (. *) #useradd \1;pass= ' echo $RANDOM | md5sum | cut-c 1-10 '; Echo ' $pass ' |passwd--stdin \1;echo-e ' \1\t ' echo ' $pass "'" >>/tmp/passwd.log#g' | Bash
Method 3:
echo template{. Ten xargs -n1 useradd; echo template{. : 'cat /dev/urandom| TR 0-9|fold-w8|head-1 ' | Xargs-n1|tee-a pass.txt|chpasswd
4, Interview questions: Write a script to determine the 192.168.8.0/24 network, the current online IP what
Method 1:
#!/bin/Bash G forIinch`seq 254` Do { Ping-C2-W2 192.168.8. $i &>/dev/NULL if[$?-eq0]; Then Echo "192.168.8. $i is Alive"?fi?}&#shell的并发检测功能, Batch ping, quick return results Done
Method 2: Use Namp (requires installation of Namp)
192.168. 8.0/awk'/nmap Scan report for/{print $NF}' #1到2秒返回结果
5. Interview question: Write a shell script to solve the problem of DDoS attack production
Depending on the number of web logs or network connections, monitor when PV reaches 100 for an IP concurrent connection or a short period of time, that is, call the firewall command to block the corresponding IP: the command for the firewall is:
Iptables-i input-s ip-j DROP
Refer to this script:
#!/bin/Bash#author Template#time2018- -- Geneva A: .file=$1Log_file=/tmp/Tmp.logjudgeext () {if Expr " $":". *\.log"&>/dev/NULL; Then : Else Echo "Usage: $ xxx.log"Exit1 fi}ipcount () {grep "established"$1|gawk-F"[ :]+" '{++s[$ (NF-3)]} END {for (key in S) print S[key],key}'|Sort-rn-k1 |Head-5>$log _file}ipt () {Local IP=$1 if[' Iptabls-l-n |grep "$ip"|WC-L '-lt1]; ThenIptabls-I input-s $ip-J DROPEcho "$line is dorpped">>/tmp/drop_list_$ (Date+%F). Logfi}main () {Judgeext $file while true DoIpcount $file whileRead Line DoIP=`Echo$line |gawk '{print $}'' Count=`Echo$line |gawk '{print $}'` if[$count-GT -]; ThenIPT $ipfi Done<$log _fileSleep the Done}main
View Code
6, Interview questions: Please use a script to implement the MySQL database sub-Library backup
#!/bin/BashEcho-E ['Date+"%y-%m-%d%h:%m:%s"'] Start#system Time Time=`Date+"%y-%m-%d"' #host iphost="127.0.0.1"#database Backup Useruser="Root"#database Passwordpasswd="yourpasswd"#Create a backup directorymkdir-p/backup/db/"$time"#list Database Nameall_database= '/usr/bin/mysql-u$user-p$passwd-bse'Show Databases'`#inchThe table from the database backup forIinch$all _database Do/usr/bin/mysqldump-u$user-p$passwd$i >/backup/db/"$time"/"$i"_"$time". SQL DoneEcho-E ['Date+"%y-%m-%d%h:%m:%s"'] Endexit0
View Code
7, Interview questions: Please use a script to implement the MySQL database sub-Library sub-table backup
#!/bin/Bashpath="/application/mysql/bin: $PATH"DBPATH=/server/Backupmyuser=Rootmypass=123456SOCKET=/data/3306/Mysql.sockmycmd="mysql-u$myuser-p$mypass-s $SOCKET"Mydump="mysqldump-u$myuser-p$mypass-s $SOCKET"[ ! -D"$DBPATH"] &&mkdir$DBPATH fordbnameinch' $MYCMD-E"Show database;"|sed '1,2d'|Egrep-V"Mysql|schema"` Do mkdir$DBPATH/${dbname}_$ (Date+%F)-P forTableinch' $MYCMD-E"show tables from $dbname;"|sed '1d'` Do$MYDUMP $dbname $table|gzip> $DBPATH/${dbname}_$ (Date+%F)/${dbname}_${table}.sql.gz Done Done
View Code
8, Interview questions: Please develop a shell script, compare the size of two integers, by the way of parameters
#!/bin/Basha=$1b=$2Usage () {Echo "usage:$0 NUM1 NUM2"Exit2}[ $# -ne2] &&{# #判断传参个数Usage}Expr$a +1&>/dev/NULL#使用expr只能计算两个整数的原理 to determine whether the passed in parameter is an integer retval_a=$?Expr$b +1&>/dev/NULLRetval_b=$?[$RETVAL _a-ne0-O $RETVAL _b-ne0] && {Echo "You must input integer"Exit1}if["$a"-lt"$b"]; ThenEcho "$a < $b"elif["$a"-gt"$b"]; ThenEcho "$a > $b"ElseEcho "$a = $b"fiExit0
View Code
Not to be continued ....
Enterprise Shell face questions and answers