shell企业面试题

1、批量创建带有随机小写字符文件程序

使用for循环在/pizza目录下创建10个html文件,其中每个文件包含10个随机小写字母加固定字母_pizza

1、思路分析:

核心是:创建10个随机小写字母

第一种:$RANDOM

  1. [root@web- /server/scripts]# echo $RANDOM
  2. 范围0- ,第一个容易被破解,使用的时候最好再加个字符串

第二种:openssl rand -base64 10

  1. [root@web- /server/scripts]# openssl rand -base64 (最后面是长度)
  2. yz+FH2zUNMlVnw==
  3. [root@web- /server/scripts]# openssl rand -base64
  4. wkfkVmliczOgoLl0z/m5S/7InZ8+4AzdHmR6t6hhE80oghRY46598L+no+HtDcHD
  5. HyvQYnBWi6nQ0GbsjafyWZps7y6JpMEA6JOwQ+HlIOICXT7YLCcI9mQa6FUE+vHR
  6. OcxHog==

第三种:date

  1. [root@web- /server/scripts]# date +%N%s()

第四种:head /dev/urandom |cksum

  1. [root@web- /server/scripts]# head /dev/urandom |cksum

第五种:uuidgen

  1. [root@web- /server/scripts]# uuidgen
  2. 218780c9-ee6f-41dc--a9a3a717cde1

第六种:cat /proc/sys/kernel/random/uuid

  1. [root@web- /server/scripts]# cat /proc/sys/kernel/random/uuid
  2. 542f71d9-b240--b61d-632083ecf6be

第七种:expect的mkpasswd

  1. [root@web- /server/scripts]# mkpasswdyum install expect -y
  2. k3WlhJ|e7
  3.  
  4. [root@web- /server/scripts]# mkpasswd -l -d -c (-l长度、-d数字、-c小写字母、-C大写字母、-s特殊字符)
  5. nebiv;bnZi6vjluvczgP

本次使用$RANDOM,前面加字符串,md5加密 ,将数字替换为字母,截取第2-第11个,共10位

  1. [root@web- ~]# echo "PIZZA$RANDOM" |md5sum|tr "0-9" "a-z"|cut -c -
  2. befdbcdaee

2、for循环创建

  1. path=/pizza
  2. [ -d $path ] || mkdir $path
  3. for n in {..}
  4. do
  5. random=`echo "PIZZA$RANDOM" |md5sum|tr "0-9" "a-z"|cut -c -`
  6. touch $path/${random}_pizza.html
  7. done

2、批量改名

将题1中的pizza都改成linux(最好用for循环实现,并且扩展名html全部改成大写)

思路分析:

1、先改一个

2、for循环

  1. name=linux
  2. path=/pizza/
  3. cd $path
  4. for file in `ls *.html`
  5. do
  6. mv $file `echo ${file/pizza.html/linux.HTML}`
  7. done

3、方法二--用一条命令

  1. [root@web- /pizza]# ls *.HTML |awk -F 'linux.HTML' '{print "mv",$0,$1"pizza.html"}' |bash

4、方法三--专业的rename

  1. [root@web- /pizza]# rename "pizza.html" "linux.HTML" *.html

3、批量创建特殊需求要求用户案例

批量创建10个系统账号 pizza01-pizza10 并设置密码(密码是随机数,要求字符和数字等混合)

思路分析:

1、创建10个账号

第一种:echo pizza{01..10}

第二种:seq -w 10

2、随机密码,题1已经讲了很多,这次用openssl rand -base64 100

3、创建用户的命令

第一种:

useradd  pizza01

echo   密码 | passwd  --stdin

第二种:chpasswd命令

格式要符合下面的形式

pizza01:passwd

pizza02:passwd

4、for循环

  1. for n in {..}
  2. do
  3. passwd=`openssl rand -base64 `
  4. useradd pizza$n
  5. echo $passwd |passwd --stdin pizza$n
  6. echo -e "pizza$n\t$passwb" >> /pizza/user.list
  7. done

或者

  1. for n in {..}
  2. do
  3. passwd=`openssl rand -base64 `
  4. useradd pizza$n
  5. echo "pizza$n:$passwd" >> /pizza/pass.log
  6. done
  7. chpasswd < /pizza/pass.log

5、优化,搞的专业一点

  1. for n in {..}
  2. do
  3. pass=`openssl rand -base64 `
  4. if `grep "pizza$n" /etc/passwd &>/dev/null` # 判断是不是存在
  5. then
  6. useradd pizza$n &&\ # &&\设置强逻辑关系
  7. echo $pass|passwd --stdin pizza$n &&\
  8. echo -e "pizza$n\t$pass" >> /pizza/user.log
  9. else
  10. echo "pizza$n is exist."
  11. fi
  12. done

优化:

  1. for n in {..}
  2. do
  3. pass=`openssl rand -base64 `
  4. if [ `grep -w "pizza$n" /etc/passwd|wc -l` -eq ]
  5. then
  6. useradd pizza$n &&\
  7. echo $pass|passwd --stdin pizza$n &&\
  8. echo -e "pizza$n\t$pass" >> /pizza/user.log
  9. echo "adduser successful"
  10.  
  11. else
  12. echo "pizza$n is exist."
  13. fi
  14. done

优化:

  1. . /etc/init.d/functions
  2. for n in {..}
  3. do
  4. pass=`openssl rand -base64 `
  5. if [ `grep -w "pizza$n" /etc/passwd|wc -l` -eq ]
  6. then
  7. useradd pizza$n &&\
  8. echo $pass|passwd --stdin pizza$n &>/dev/null &&\
  9. echo -e "pizza$n\t$pass" >> /pizza/user.log
  10. action "adduser successful" /bin/true
  11.  
  12. else
  13. action "pizza$n is exist." /bin/false
  14. fi
  15. done

优化:

  1. . /etc/init.d/functions
  2. if [ $UID -ne ]
  3. then
  4. echo "必须用root执行本脚本"
  5. exit
  6. fi
  7.  
  8. for n in {..}
  9. do
  10. pass=`openssl rand -base64 `
  11. if [ `grep -w "pizza$n" /etc/passwd|wc -l` -eq ]
  12. then
  13. useradd pizza$n &&\
  14. echo $pass|passwd --stdin pizza$n &>/dev/null &&\
  15. echo -e "pizza$n\t$pass" >> /pizza/user.log
  16. action "adduser successful" /bin/true
  17.  
  18. else
  19. action "pizza$n is exist." /bin/false
  20. fi
  21. done

6、不用for循环的实现

http://user.qzone.qq.com/49000448/blog/1422183723

4、扫描网络内存活主机

写一个Shell脚本,判断10.0.0.0/24网络里面,当前在线的IP有哪些

思路分析

1、判断主机存活

  1. ping c i w 10.0.0.7
  2. nmap -sP 10.0.0.0/

2、搞起来

第一种:ping

  1. for n in {..}
  2. do
  3. # 将整个执行用大括号括起来 加 &,进行批量ping,原理就是放到后台执行
  4. {
  5. if `ping -c -w 10.0..$n &>/dev/null`
  6. then
  7. echo "10.0.0.$n is up"
  8. else
  9. echo "10.0.0.$n is down"
  10. fi
  11. } &
  12. done

# 没有进行过滤,所以输出很多,可以优化一下
第二种:使用nmap命令行就可以

  1. [root@web- /server/scripts]# nmap -sP 10.0.0.0/ |awk '/Nmap scan report for/{print $NF}'

5、MySQL分库备份

实现对MySQL数据库进行分库备份,用脚本实现

为什么要进行分库备份呢,因为,如果在以后需要备份一个小库,就会很麻烦

常规方法:

  1. mysqldump -B userinfo click test | gzip >bak.sql.gz

分库备份:

  1. mysqldump -B userinfo | gzip >bak.sql.gz
  2. mysqldump -B click | gzip >bak.sql.gz
  3. mysqldump -B test | gzip >bak.sql.gz

执行命令获取库名

  1. mysql -uroot -ppizza123 -e "show databases" | grep -v _schema | sed 1d

把密码放到配置文件中

  1. cat /etc/my.cnf
  2. [client]
  3. user = root
  4. passwd = pizza123

做完这一步就不用在脚本中添加-u和-p参数

备份脚本

  1. path=/backup
  2. mysql="mysql -uroot -ppizza123"
  3. mysqldump="mysqldump -uroot -ppizza123"
  4. [ -d $path ] || mkdir $path
  5. for dbname in `$mysql -e "show databases;" >/dev/null|grep -v _schema | sed 1d`
  6. do
  7. # 这个命令还有很多参数没有写
  8. $mysqldump -B $dbname |gzip >/backup/${dbname}_$(date +%F).sql.gz
  9. done

6、MySQL分库、分表备份

常规备份

  1. mysqldump pizza test test1 | gzip > bak.sql.gz
  2.  
  3. pizza是库名、testtest1是表名

分库、分表备份

  1. mysqldump -B pizza | gzip >bak.sql.gz
  2. mysqldump pizza test1
  3. mysqldump pizza test2
  4. mysqldump pizza test3

脚本编码

  1. path=/backup
  2. mysql="mysql -uroot -ppizza123"
  3. mysqldump="mysqldump -uroot -ppizza123"
  4. [ -d $path ] || mkdir $path
  5. for tname in `$mysql -e "show tables from $dbname;" >/dev/null|sed 1d`
  6. do
  7. if [ "$dbname" = "mysql" ]
  8. then
  9. # 这个命令还有很多参数没有写
  10. $mysqldump --skip-lock-tables $dbname $tname |gzip >$path/${dbname}-$tname_$(date +%F).sql.gz >/dev/null
  11. else
  12. $mysqldump $dbname $tname |gzip >$path/${dbname}-$tname_$(date +%F).sql.gz >/dev/null
  13. fi
  14. done
  15. done

7、SSH服务批量分发与管理服务

确保主机能用root登陆

  1. vim /etc/ssh/sshd_config 字段 PermitRootLogin yes

建立密钥对

  1. ssh-keygen

发送公钥到其他服务器

  1. ssh-copy-id -i id_rsa.pub 10.0.0.8

可能会很慢,调整其他机器的配置,让操作快一些

  1. useDNS no
  2.  
  3. GSSAPIAuthentication no

重启服务,继续

  1. ssh-copy-id -i id_rsa.pub 10.0.0.8
  2.  
  3. ssh-copy-id -i id_rsa.pub 10.0.0.9

写一个链接主机并可以执行命令的脚本

vim ssh_.sh

  1. if [ $# -ne ]
  2. then
  3.   echo "usage:$0 cmd"
  4.   exit
  5. fi
  6. for n in
  7. do
  8.   echo "-----10.0.0.$n------"
  9.   ssh 10.0..$n $
  10. done

执行脚本

  1. bash ssh_.sh "free -m"

编写分发脚本

  1. . /etc/init.d/functions
  2. if [ $# -ne ]
  3. then
  4. echo "usage:$0 localdir remotedir"
  5. exit
  6. fi
  7.  
  8. for n in
  9. do
  10. scp -rp $ 10.0..$n:$ &>/dev/null
  11. if [ $? -eq ]
  12. then
  13. action "10.0.0.$n sucessful" /bin/true
  14. else
  15. actin "10.0.0.$n fail" /bin/false
  16. fi
  17. done

8、破解RANDOM随机数案例

已知下面这些字符串是通过RANDOM随机变量 md5sum 后,再截取一部分连续字符串的结果,亲个破解这些字符串对用的使用md5sum 处理前的RANDOM对应的数字

21023299

00205d1c

a3da1677

1f6d12dd

890684b

解答:

1、分析

RANDOM的随机范围是0-32767 。

显现需要把范围内的数字都加密,输出到md5.log中

2、比较

  1. grep 890684b md5.log | wc -l

3、编码实现

  1. array=(
  2.  
  3. 00205d1c
  4. a3da1677
  5. 1f6d12dd
  6. 890684b
  7. )
  8. md5(){
  9. for n in {..}
  10. do
  11. echo -e "$n\t`echo $n|md5sum`" >> /pizza/md5.log
  12. done
  13.  
  14. }
  15. crack_num(){
  16. for num in ${array[*]}
  17. do
  18. find=`grep $num /pizza/md5.log`
  19. if [ `echo $find|wc -l` -eq ]
  20. then
  21. echo $find
  22. fi
  23. done
  24. }
  25. main(){
  26. md5
  27. crack_num
  28. }
  29. main

第二种方法:egrep实现

  1. [root@web- /server/scripts]# array=(
  2. >
  3. > 00205d1c
  4. > a3da1677
  5. > 1f6d12dd
  6. > 890684b
  7. > )
  8.  
  9. [root@web- /server/scripts]# cmd=`echo ${array[*]}|tr " " "|"`
  10.  
  11. [root@web- /server/scripts]# egrep "$cmd" /pizza/md5.log

修改第一版

  1. array=(
  2.  
  3. 00205d1c
  4. a3da1677
  5. 1f6d12dd
  6. 890684b
  7. )
  8. md5(){
  9. for n in {..}
  10. do
  11. echo -e "$n\t`echo $n|md5sum`" > /pizza/md5.log &
  12. done
  13.  
  14. }
  15. crack_num(){
  16. cmd=`echo ${array[*]}|tr " " "|"`
  17. egrep "$cmd" /pizza/md5.log
  18. }
  19.  
  20. main(){
  21. md5
  22. crack_num
  23. }
  24. main

利用time命令对比两个版本的时间

time sh 8_random_crack.sh

9、检查多个网站地址是否正常

要求

1、使用shell数组方法,检测策略精良模拟用户访问

2、每10秒种做一次所有的检测,无法访问的输出报警

3、待检测网址如下

https://www.cnblogs.com/yxiaodao/

https://www.baidu.com/

检测工具:

url

curl

wget

脚本编码

  1. . /etc/init.d/functions
  2. url=(
  3. https://www.cnblogs.com/yxiaodao/
  4. https://www.baidu.com/
  5. )
  6. check_url(){
  7. wget -t -T -o /dev/null -q $
  8. if [ $? -eq ]
  9. then
  10. action "$1 is ok" /bin/true
  11. else
  12. action "$1 is lost" /bin/false
  13. fi
  14. }
  15.  
  16. DealUrl(){
  17. for url in ${url[*]}
  18. do
  19. check_url $url
  20. done
  21. }
  22.  
  23. main(){
  24. while true
  25. do
  26. DealUrl
  27. sleep
  28. done
  29.  
  30. }
  31. main

修改题目,不用数组,将网址放在文件中,做如下修改

  1. DealUrl(){
  2. while read line
  3. do
  4. check_url $line
  5. done < ./pizza/url.log
  6. }

有一个问题,在我们操作完后,会产生大量的网页文件,因为我们的命令将网页下载了

需要在命令中添加参数 -- spider

10、利用Shell编程分析Web日志解决Dos攻击生产案例

DOS  Deny  of  Service

DDOS  分布式dos攻击

请根据web日志或者网络连接数,监控当某个IP并发连接数或者短时间内PV达到100(根据实际情况设定),即调用防火墙命令封掉对应的IP。

防火墙命令:iptables  -l  INPUT  -s  IP地址  -j  DROP

分析:

1、web日志或者网络连接数

  日志文件,netstat  -an | grep  -i  est,排序去重

2、判断PV 或者连接数大于100 ,取出IP ,封IP

IP 在日志的第一列,取到IP---->排序---->统计数量----> 按数量从大到小排序

  1. [root@web- /server/scripts]# awk '{print $1}' access_2010--.log |sort|uniq -c|sort -rn
  2. 59.33.26.105
  3. 123.122.65.226
  4. 124.115.4.18

也能通过awk的数组来完成

  1. [root@web- /server/scripts]# awk '{S[$1]++}END{for(key in S) print S[key],key}' access_2010--.log |sort -rn
  2. 59.33.26.105
  3. 123.122.65.226
  4. 124.115.4.18

编码脚本

  1. awk '{S[$1]++}END{for(key in S) print S[key],key}' access_2010--.log |sort -rn > /pizza/ip.log
  2. while read line
  3. do
  4. ip=`echo $line|awk '{print $2}'`
  5. count=`echo $line|awk '{print $1}'`
  6. if [ $count -gt -a `grep $ip /pizza/drop.log|wc -l` -lt ]
  7. then
  8. iptables -I INPUT -s $ip -j DROP &&\
  9. echo "$ip" >>/pizza/drop.log
  10. else
  11. echo "$ip" >>/pizza/accept.log
  12. fi
  13. done</pizza/ip.log

本次采用了读取drop.log日志的方法,也可以采用查看 iptables -nL的方法

10、利用Shell编程分析Linux服务器网络链接数解决DOS攻击生产案例实践

还是上一个题,上面的题监控的是web日志,本次是监控网络链接数实现

命令:ESTABLISHED 正在建立的链接状态

  1. [root@web- /server/scripts]# netstat -an |grep -i ESTABLISHED
  2. Active Internet connections (servers and established)
  3. tcp 172.17.214.84: 107.175.240.135: ESTABLISHED
  4. tcp 172.17.214.84: 100.100.30.25: ESTABLISHED
  5. tcp 172.17.214.84: 163.125.30.51: ESTABLISHED
  6. Active UNIX domain sockets (servers and established)

获取外部地址,统计,排序(为方便,将命令的输出到了日志)

  1. [root@web- ~]# awk '/ESTAB/{print $0}' netstat.log|awk -F "[ :]+" '{print $(NF-3)}'|sort|uniq -c|sort -rn

高级写法,通过awk数组

  1. [root@web- ~]# awk -F "[ :]+" '/ESTAB/{S[$(NF-3)]++}END{for(k in S) print S[k],k}' netstat.log | sort -rn |head

不用日志,用netstat -an

  1. [root@web- ~]# netstat -an|awk -F "[ :]+" '/ESTAB/{S[$(NF-2)]++}END{for(k in S) print S[k],k}' | head
  2. 163.125.30.51
  3. 100.100.30.25
  4. 107.175.240.135
    因数据差异,具体命令中参数还要自己调

脚本编写,只需修改前一个脚本的第一行获取ip的命令即可

  1. netstat -an|awk -F "[ :]+" '/ESTAB/{S[$(NF-2)]++}END{for(k in S) print S[k],k}'|head >/pizza/ip.log
  2.  
  3. while read line
  4. do
  5. ip=`echo $line|awk '{print $2}'`
  6. count=`echo $line|awk '{print $1}'`
  7. if [ $count -gt -a `grep $ip /pizza/drop.log|wc -l` -lt ]
  8. then
  9. iptables -I INPUT -s $ip -j DROP &&\
  10. echo "$ip" >>/pizza/drop.log
  11. else
  12. echo "$ip" >>/pizza/accept.log
  13. fi
  14. done</pizza/ip.log
    在实际工作中,可以设置定时任务,每3分钟执行一次,每天晚上0点取消

11、开发MySQL服务启动停止脚本

要求:用函数,case语句,if语句等实现 /etc/init.d/mysqld  {start | stop | restart} 命令

分析:

1、启动

mysqld_safe  --user=mysql &

2、停止

mysqladmin  -uroot  -ppasswd  shutdown

killall,pkill(参考之前写的rsync 第九章-case结构条件句)

3、脚本编码

看一下mysql的pid的文件位置

  1. # 定义锁文件
  2. lockfile=/var/lock/subsys/mysqld
  3. # 定义变量,指定mysqld的的pid,是需要自己mysql的conf中去创建
  4. mysql_pid_file_path=/application/mysql/data/`uname -n.pid`
  5. . /etc/init.d/functions
  6. start(){
  7. mysql_safe --user=mysql &>/dev/null &
  8. retval=$?
  9. if [ $retval -eq ]
  10. then
  11. action "mysql startup ok" /bin/true
  12. touch $lockfile
  13. return $retval
  14. else
  15. action "mysql startup fail" /bin/false
  16. return $retval
  17. fi
  18. }
  19. stop(){
  20. if test -s "$mysql_pid_file_path"
  21. then
  22. mysql_pid=`cat $mysql_pid_file_path`
  23. if (kill - $mysql_pid &>/dev/null)
  24. then
  25. # 为了在重复停止操作的时候,不提示,将其扔到黑洞
  26. kill $mysql_pi
  27. retval=$?
  28. if [ $? -eq ]
  29. then
  30. action "mysql stop ok" /bin/true
  31. rm -f $lockfile
  32. return $retval
  33. else
  34. action "mysql stop fail" /bin/false
  35. return $retval
  36. fi
  37. else
  38. echo "mysqld_process is not exit."
  39. return
  40. fi
  41. else
  42. echo "$mysqld_pid_file_path is not exist,or mysqld does not startup"
  43. fi
  44.  
  45. }
  46. restart(){
  47. killall mysql && sleep && mysql --deamon
  48. retval=$?
  49. if [ $? -eq ]
  50. then
  51. action "mysql restart ok" /bin/true
  52. return $retval
  53. else
  54. action "mysql restart fail" /bin/false
  55. return $retval
  56. fi
  57. }
  58. case "$1" in
  59. start)
  60. start
  61. # 我了向外传值
  62. retval=$?
  63. ;;
  64. stop)
  65. stop
  66. retval=$?
  67. ;;
  68. restart)
  69. stop
  70. sleep
  71. start
  72. retval=$?
  73. ;;
  74.  
  75. *)
  76. echo "usage:$0 {start|stop|restart}"
  77. exit
  78. esac
  79. exit $retval

出现问题,启动了,但是没有pid文件

解决:

1、先使用系统的命令开启。

2、通过查看ps -ef |grep mysql 查看 启动参数

添加启动参数 --pid-file=$mysql_pid_file_path

问题:进不去mysql

添加参数--datedir=/application/mysql/data

问题:启动的过程很快,执行脚本后,启动成功,但是没有发现进程和pid,无法进入

1、查看mysql日志

cat /application/mysql/data/web01.err

2、发现使用脚本中的命令,手动也起不来

3、使用系统执行后的启动命令

/bin/sh  /application/masql/bin/mysqld_safe  --datedir=/application/mysql/data  --pid-file=$mysql_pid_file_path

脚本一定要现在命令行测试成功,再写入脚本中

最后一个任务

拷贝到/etc/init.d中 ,变成chkconfig 可已使用的脚本

12、按单词去重排序

  1. In the world of hackers, the kind of answers you get to your technical questions depends as much on the way you ask the questions as on the difficulty of developing the answer. This guide will teach you how to ask questions in a way more likely to get you a satisfactory answer.
  2. Now that use of open source has become widespread, you can often get as good answers from other, more experienced users as from hackers. This is a Good Thing; users tend to be just a little bit more tolerant of the kind of failures newbies often have. Still, treating experienced users like hackers in the ways we recommend here will generally be the most effective way to get useful answers out of them, too.
  3. The first thing to understand is that hackers actually like hard problems and good, thought-provoking questions about them. If we didn't, we wouldn't be here. If you give us an interesting question to chew on we'll be grateful to you; good questions are a stimulus and a gift. Good questions help us develop our understanding, and often reveal problems we might not have noticed or thought about otherwise. Among hackers, “Good question!” is a strong and sincere compliment.
  4. Despite this, hackers have a reputation for meeting simple questions with what looks like hostility or arrogance. It sometimes looks like we're reflexively rude to newbies and the ignorant. But this isn't really true.
  5. What we are, unapologetically, is hostile to people who seem to be unwilling to think or to do their own homework before asking questions. People like that are time sinks — they take without giving back, and they waste time we could have spent on another question more interesting and another person more worthy of an answer. We call people like this “losers” (and for historical reasons we sometimes spell it “lusers”).
  6. We realize that there are many people who just want to use the software we write, and who have no interest in learning technical details. For most people, a computer is merely a tool, a means to an end; they have more important things to do and lives to live. We acknowledge that, and don't expect everyone to take an interest in the technical matters that fascinate us. Nevertheless, our style of answering questions is tuned for people who do take such an interest and are willing to be active participants in problem-solving. That's not going to change. Nor should it; if it did, we would become less effective at the things we do best.
  7. We're (largely) volunteers. We take time out of busy lives to answer questions, and at times we're overwhelmed with them. So we filter ruthlessly. In particular, we throw away questions from people who appear to be losers in order to spend our question-answering time more efficiently, on winners.
  8. If you find this attitude obnoxious, condescending, or arrogant, check your assumptions. We're not asking you to genuflect to us in fact, most of us would love nothing more than to deal with you as an equal and welcome you into our culture, if you put in the effort required to make that possible. But it's simply not efficient for us to try to help people who are not willing to help themselves. It's OK to be ignorant; it's not OK to play stupid.
  9. So, while it isn't necessary to already be technically competent to get attention from us, it is necessary to demonstrate the kind of attitude that leads to competence alert, thoughtful, observant, willing to be an active partner in developing a solution. If you can't live with this sort of discrimination, we suggest you pay somebody for a commercial support contract instead of asking hackers to personally donate help to you.
  10. If you decide to come to us for help, you don't want to be one of the losers. You don't want to seem like one, either. The best way to get a rapid and responsive answer is to ask it like a person with smarts, confidence, and clues who just happens to need help on one particular problem.

按单词出现的频率降序排序

1、把空格和符号都转换成空格--排序--统计--排序

2、命令

  1. [root@web- /server/scripts]# cat english.txt |tr "“”! ,.)( " "\n" |sort|uniq -c |sort -rn

方法二:

  1. [root@web- /server/scripts]# cat english.txt |tr "“”! ,.)( " "\n" |awk '{S[$1]++}END{for(k in S) print S[k],k}'|sort -rn

方法三:

  1. cat english.txt |xargs -n1

12、按字母去重排序

按字母出现的频率降序排序

1、使用 grep -o ‘.’  匹配任意 之后,会挨个输出 或者 grep -o "[^ ]"

  1. grep -o "[^ ,.()]" english.txt |awk '{S[$1]++}END{for(k in S) print S[k],k}'|sort -rn

2、awk可以用空做分隔符

  1. sed 's#[ ,\.\]##g' english.txt|awk -F "" '{for(i=0;i<NF;i++)S[$i]++}END{for(k in S) print S[k],k}' |sort -rn

暂时没有设计出过滤换换行符

13、按单词去重排序高级方案

基于上面的awk统计单词

  1. awk -F "[ ,.]" '{for(i=1;i<NF;i++)S[$i]++}END{for(k in S) print S[k],k}' english.txt |sort -rn

教学例题讲解

word文档

合格的运维人员必会的脚本列表

1)系统及各类服务的监控脚本,例如:文件、内存、磁盘、端口,URL监控报警等。

2)监控网站目录下文件是否被篡改,以及站点目录批量被篡改后如何批量恢复的脚本。

3)各类服务Rsync、Nginx、MySQL等的启动及停止专业脚本(使用chkconfig管理)。

4)MySQL主从复制监控报警以及自动处理不复制故障的脚本。

5)一键配置MySQL多实例、一键配置MySQL主从部署脚本。

6)监控HTTP/MySQL/Rsync/NFS/Memcached等服务是否异常的生产脚本。

7)一键软件安装及优化的脚本,比如LANMP、Linux一键优化,一键数据库安装、优化等。

8)MySQL多实例启动脚本,分库、分表自动备份脚本。

9)根据网络连接数以及根据Web日志PV封IP的脚本。

10)监控网站的PV以及流量,并且对流量信息进行统计的脚本。

11)检查Web服务器多个URL地址是否异常的脚本,要可以批量处理且通用。

12)系统的基础优化一键优化的脚本。

13)TCP连接状态及IP统计报警脚本。

14)批量创建用户并设置随机8位密码的脚本

Shell企业案例实战和企业面试题的更多相关文章

  1. shell编程企业级实战(2)

    Vim配置文件.vimrc vim配置文件 if 条件语句 if是最常见的条件判断语句 例1:如果不存在/backup目录就创建. [root@web-01 /server/tools]# vim 0 ...

  2. shell编程企业级实战

    如何才能学好Shell编程 为什么要学习shell编程 Shell是Linux底层核心 Linux运维工作常用工具 自动化运维必备基础课程 学好shell编程所需Linux基础 熟练使用vim编辑器 ...

  3. Linux实战型企业运维工程师试题测评

    Linux实战型企业运维工程师试题答案 作者:尹正杰      最近在网上看到了一套有意思的面试题,我们一起来看一下这些题怎么破吧,哈哈~我先放在这里,有时间了一起来看看.多学点东西终究是没有坏处的! ...

  4. Snort企业部署实战

    Snort企业部署实战 1 背景       我们知道企业网络目前威胁来自两个位置:一个是内部,一个是外部.来自外部的威胁都能被防火墙所阻止,但内部攻击都不好防范.因为公司内部人员对系统了解很深且有合 ...

  5. 轻量级Java EE企业应用实战(第4版):Struts 2+Spring 4+Hibernate整合开发(含CD光盘1张)

    轻量级Java EE企业应用实战(第4版):Struts 2+Spring 4+Hibernate整合开发(含CD光盘1张)(国家级奖项获奖作品升级版,四版累计印刷27次发行量超10万册的轻量级Jav ...

  6. 企业案例:查找当前目录下所有文件,并把文件中的https://www.cnblogs.com/zhaokang2019/字符串替换成https://www.cnblogs.com/guobaoyan2019/

    企业案例:查找当前目录下所有文件,并把文件中的https://www.cnblogs.com/zhaokang2019/字符串替换成https://www.cnblogs.com/guobaoyan2 ...

  7. MongoDb企业应用实战(一) 写在MongoDb应用介绍之前(i)

    故事背景: 本人有幸,经老友( 现为x知名快递公司技术总监 ) 推荐进入中国前三大民营快递公司之一工作,在此非常感谢他,在此也非常感谢我在第一家公司帮助我进步的兄弟(我在时的项目经理,现为 x  知名 ...

  8. 20.Linux进程管理-企业案例

    1.管理进程状态 当程序运行为进程后,如果希望停止进程,怎么办呢? 那么此时我们可以使用linux的kill命令对进程发送关闭信号.当然除了kill.还有killall,pkill 1.使用kill ...

  9. 图书-技术-SpringBoot:《Spring Boot2 + Thymeleaf 企业应用实战》

    ylbtech-图书-技术-SpringBoot:<Spring Boot2 + Thymeleaf 企业应用实战> <Spring Boot 2+Thymeleaf企业应用实战&g ...

随机推荐

  1. Linux 用户及权限详解

    Linux 用户及权限详解 用户 , 组 ,权限 安全上下文(secure context): 权限: r,w,x 文件: r : 可读,可以使用类似cat 等命令查看文件内容. w : 可写,可以编 ...

  2. 开源:ASP.NET Aries 开发框架(已支持.NET Core)

    前言: 随着岁月的推进,不知不觉已在.NET这领域上战斗了十年了. 青春还没来得急好好感受,却已是步入健忘之秋的老人一枚了. 趁着还有点记忆,得赶紧把硬盘里那私藏的80G除外的东西,和大伙分享分享. ...

  3. 文本离散表示(二):新闻语料的one-hot编码

    上一篇博客介绍了文本离散表示的one-hot.TF-IDF和n-gram方法,在这篇文章里,我做了一个对新闻文本进行one-hot编码的小实践. 文本的one-hot相对而言比较简单,我用了两种方法, ...

  4. FragmentTabHostTopDemo【FragmentTabHost固定宽度且居中】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 使用FragmentTabHost实现顶部选项卡(居中且宽度非全屏)展现. 备注:该Demo主要是演示FragmentTabHost ...

  5. PhotoPickerNewDemo【PhotoPicker0.9.12的个性化修改以及使用(内部glide版本号是4.1.1)】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 本Demo使用的是PhotoPicker 0.9.12版本,里面集成的glide版本号是4.1.1.这里就不进行特殊的个性化处理了( ...

  6. Python--开发简单爬虫

    简单爬虫架构 动态运行流程 URL管理器的作用 URL管理器的3种实现方式 网页下载器的作用 Python网页下载器的种类 urllib2下载网页的3种方法 网页解析器的作用 Python的几种网页解 ...

  7. Elasticsearch的基本概念和指标

    背景 在13年的时候,我开始负责整个公司的搜索引擎.嗯……,不是很牛的那种大项目负责人.而是整个搜索就我一个人做.哈哈. 后来跳槽之后,所经历的团队都用Elasticsearch,基本上和缓存一样,是 ...

  8. 学习ASP.NET Core Razor 编程系列十九——分页

    学习ASP.NET Core Razor 编程系列目录 学习ASP.NET Core Razor 编程系列一 学习ASP.NET Core Razor 编程系列二——添加一个实体 学习ASP.NET ...

  9. 一致性Hash漫画图解

    一年之前—— 未来两年内,系统预估的总订单数量可达一亿条左右. 按Mysql单表存储500万条记录来算,暂时不必分库,单库30个分表是比较合适的水平分表方案. 于是小灰设计了这样的分表逻辑: 订单表创 ...

  10. 4.5管道实现机制和模拟构建管道「深入浅出ASP.NET Core系列」

    希望给你3-5分钟的碎片化学习,可能是坐地铁.等公交,积少成多,水滴石穿,谢谢关注. 管道实现机制 要了解管道的实现机制,我们必须要深入框架的源码,幸亏微软开源了,我们可以访问GitHub的地址来下载 ...