博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Shell面试题
阅读量:7028 次
发布时间:2019-06-28

本文共 5325 字,大约阅读时间需要 17 分钟。

11-12 Shell练习题

1、中企动力面试题

用shell处理以下内容

1、按单词出现频率降序排序!
2、按字母出现频率降序排序!

the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections for more infomation
#!/usr/bin/bash############################################################### File Name: tongji.sh# Version: V1.0# Author: CentOS# Organization: http://47.94.88.182/# Created Time : 2018-11-12 11:13:17# Description:##############################################################zimu=`echo 'the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections for more infomation'|sed -r 's#[.,]# #g'`echo $zimu|xargs -n1|awk '{array[$1]++}END{for(j in array)print j,array[j]}'|sort -k2 -rn|column -techo $zimu|egrep -o "[a-Z]"|sort|uniq -c |sort -nr |column -t

2、企业面试题

已知下面的字符串是通过RANDOM随机数变量md5sum|cut-c 1-8截取后的结果,请破解这些字符串对应的md5sum前的RANDOM对应数字?

2102929900205d1ca3da16771f6d12dd

解答:利用random的范围(0-32767)

#!/bin/basha=(2102929900205d1ca3da16771f6d12dd)for n in {0..32767}do        random=`echo $n|md5sum|cut -c1-8`        for((i=0;i<=${#a[@]};i++))        do          if [ "$random" == "${a[i]}" ];then          echo "$n" "${a[i]}"        fi        donedone

3、使用for循环在/oldboy目录下批量创建10个html文件

通过随机小写10个字母加固定字符串oldboy批量创建10个html文件

mkdir /oldboy && cd /oldboy && for i in `seq 10`;do a=`echo $RANDOM|md5sum|tr "0-9" "j-z"|cut -c1-10`;touch ${a}_oldboy.html;done

4、请用至少两种方法实现!

将以上文件名中的oldboy全部改成oldgirl(用for循环实现),并且html改成大写。

rename的方法

cd /oldboy && rename _oldboy.html _oldgirl.HTML *

sed命令拼接

cd /oldboy/ && ls  |sed -r 's#(.*)_(.*)#mv \1_\2 \1_oldgirl.HTML#'|bash

for循环

cd /oldboyfor i in `find /oldboy -type f -name  "*_oldboy.html"`dob=`echo $i|cut -c 1-19`mv ${b}oldboy.html ${b}oldgirl.HTMLdonecd /oldboyfor i in `find /oldboy -type f -name  "*_oldboy.html"`dob=`echo $i |sed -r 's#(.*)oldboy.html#\1#g'`mv ${b}oldboy.html ${b}oldgirl.HTMLdone

5、写一个脚本,实现判断10.0.0.0/24网络里,当前在线用户的IP有哪些

方法有很多种

#!/usr/bin/bash############################################################### File Name: ip.sh# Version: V1.0# Author: CentOS# Organization: http://47.94.88.182/# Created Time : 2018-11-09 11:07:50# Description:##############################################################source /etc/init.d/functionsIP=10.0.0.for j in {1..254}doping -c 1 -w 2s $IP$j &>/dev/nullif [ $? -eq 0 ];then        action "$IP$j " else        action "$IP$j" /bin/falsefidone

6、请用至少两种方法实现!循环、数组方式

for循环打印下面这句话中字母数不大于6的单词(昆仑万维面试题)。

I am oldboy teacher welcome to oldboy training class.

方法一

#!/bin/shfor i in I am oldboy teacher welcome to oldboy training class.do        if [ ${#i} -lt 6 ];then        echo $i        fidone

方法二

echo "I am oldboy teacher welcome to oldboy training class."|xargs -n1|awk '{if(length<6)print}'

方法三

echo "I am oldboy teacher welcome to oldboy training class."|awk '{for(i=1;i<=NF;i++)if(length($i)<6)print $i}'

7、开发shell脚本分别实现以脚本传参以及read读入的方式比较2个整数大小。

以屏幕输出的方式提醒用户比较结果。当用脚本传参以及read读入的方式需要对变量是否为数字、并且传参个数做判断。

read读入的方式

#!/bin/bashread -p "Please input two Number: " -a Arr_strecho ${Arr_str[*]} | grep -E "^[0-9 ]{1,}$" &>/dev/null || exit if [ ${#Arr_str[*]} -eq 2 ];then   if [ ${Arr_str[0]} -eq ${Arr_str[1]} ];then        echo "${Arr_str[0]} == ${Arr_str[1]}"   elif [ ${Arr_str[0]} -gt ${Arr_str[1]} ];then        echo "${Arr_str[0]} > ${Arr_str[1]}"   else        echo "${Arr_str[0]} < ${Arr_str[1]}"   fielse    echo "Please input two Number" fi

脚本传参的方式

#!/usr/bin/bash############################################################### File Name: panduan.sh# Version: V1.0# Author: CentOS# Organization: http://47.94.88.182/# Created Time : 2018-11-13 20:12:54# Description: ##############################################################   echo $1 | grep -E "^[0-9 ]{1,}$" &>/dev/null || exitecho $2 | grep -E "^[0-9 ]{1,}$" &>/dev/null || exitif [ $# -eq 2 ];then   if [ $1 -eq $2 ];then        echo "$1 == $2"   elif [ $1 -gt $2 ];then        echo "$1 > $2"   else        echo "$1 < $2"   fielse    echo "Please input two Number" fi

8、面试及实战考试题:监控web站点目录下所有文件

是否被恶意篡改(文件内容被改了)

web站点目录(/var/html/www)
如果有就打印改动的文件名(发邮件),定时任务每3分钟执行一次。

find /var/html/www/ -type f -name "*.thml"|xargs md5sum >/tmp/a.logmd5sum -c /tmp/a.log

9、老男孩教育天津项目学生实践抓阄题目:

好消息,老男孩培训学生外出企业项目实践机会(第6次)来了(本月中旬),但是,名额有限,队员限3人(班长带队)。

因此需要挑选学生,因此需要一个抓阄的程序:

要求:1、执行脚本后,想去的同学输入英文名字全拼,产生随机数01-99之间的数字,数字越大就去参加项目实践,前面已经抓到的数字,下次不能在出现相同数字。2、第一个输入名字后,屏幕输出信息,并将名字和数字记录到文件里,程序不能退出继续等待别的学生输入,抓完输入exit退出。
#!/usr/bin/bash############################################################### File Name: ces.sh# Version: V1.0# Author: CentOS# Organization: http://47.94.88.182/# Created Time : 2018-11-12 16:22:39# Description:##############################################################declare -A arrarr[banzhang]=100while truedo    [ "$Name" = "quit" ] && break    read -p "Please input you name: " Name    while true     do      Num=`echo $(($RANDOM%100+1))`      if [[ $Num =~ ${arr[*]} ]];then          continue      else          arr[$Name]=$Num          echo "$Name" "$Num"          break      fi    donedonefor j in ${!arr[*]}do  echo $j ${arr[$j]} >>/tmp/zhuajiu.txtdonesort -nr -k2 /tmp/zhuajiu.txt|head -4 |column -t

10、计算从1加到100之和

seq 100|awk '{i=i+$1}END{print i}'

转载于:https://www.cnblogs.com/wenrulaogou/p/9954455.html

你可能感兴趣的文章
Win8 官方培训课程
查看>>
用MacBook对交换机进行初始化配置
查看>>
Linux 的五个重启命令及具体说明
查看>>
Hadoop虚拟化扩展(HVE)之资源扩展技术
查看>>
Exchange日常管理之十九:配置邮件提示功能
查看>>
论脚本时代:盘点那些节省时间的自动化软件
查看>>
虚拟资源引流变现
查看>>
Powershell管理系列(三)2012 AD域用户UPN名称还原
查看>>
C#设计模式(13)——代理模式(Proxy Pattern)
查看>>
K8S集群基于metrics server的HPA测试
查看>>
Linux哲学思想:组合小软件完成大任务
查看>>
Windows Thin PC安装功能组件
查看>>
管理是资产?不,管理是负债
查看>>
配置和访问终端服务RemoteApp
查看>>
python wx 的wx.Frame框架属性
查看>>
Cisco网络设备远程管理端口乾坤大挪移
查看>>
动态多点*** 单云双HUB
查看>>
OpenStack云第一天
查看>>
职场三问
查看>>
AB(apache benchmark)压力测试
查看>>