几道shell面试题及答案
2016-05-16 10:38
756 查看
企业面试题1:已知下面的字符串是通过RANDOM随机数变量md5sum|cut-c 1-8截取后的结果,请破解这些字符串对应的md5sum前的RANDOM对应数字?2102929900205d1ca3da16771f6d12dd890684b 解题思路:通过每次传递一个参数的方式,来实现依次破解 $RANDOM的范围为0-32767
7041 and 1f6d12dd
25345 and a3da1677
25667 and 21029299
企业面试题2:批量检查多个网站地址是否正常 要求:shell数组方法实现,检测策略尽量模拟用户访问思路http://www.baidu.com http://www.taobao.com http://www.51liuzw.com http://192.168.50.199
企业面试题3::用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 1.按单词出现频率降序排序! 解决思路:把空格换为换行符,并排序统计
#!/bin/bash #Author: liuwei #Site: www.51liuzw.com for n in {0..32767} do MD5=`echo $n | md5sum | cut -c 1-8` if [ "$MD5" == "$1" ];then echo "$n is." exit else echo "$n no." fi done注:也可以通过定义数组的方法,来一次全部对比
#!/bin/bash #Author: liuwei #Site: www.51liuzw.com array=( 00205d1c 21029299 a3da1677 1f6d12dd 890684b ) for n in {0..32767} do MD5=`echo $n | md5sum | cut -c 1-8` for i in ${array[@]};do if [ "$MD5" == "$i" ];then echo "$n and $i" >> c.log break else echo "$n no." fi done done#cat c.log 1346 and 00205d1c
7041 and 1f6d12dd
25345 and a3da1677
25667 and 21029299
企业面试题2:批量检查多个网站地址是否正常 要求:shell数组方法实现,检测策略尽量模拟用户访问思路http://www.baidu.com http://www.taobao.com http://www.51liuzw.com http://192.168.50.199
#!/bin/bash #Author: liuwei #Site: www.51liuzw.com array=( http://www.baidu.com http://www.taobao.com http://www.51liuzw.com http://192.168.50.199 ) for n in ${array[*]};do URL=`curl -I -m 2 $n 2> /dev/null | egrep "200|302" | wc -l` if [ "$URL" -eq 1 ];then echo "$n is OK" else echo "$n is not OK" fi done结果: #sh test.sh http://www.baidu.com is OK http://www.taobao.com is OK http://www.51liuzw.com is not OK http://192.168.50.199 is not OK
企业面试题3::用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 1.按单词出现频率降序排序! 解决思路:把空格换为换行符,并排序统计
#sed 's# #\n#g' c.txt | sort | uniq -c2.按字母出现频率降序排序! 解决思路:使用grep -o "\w",把单词拆开并去除种各符号
#cat c.txt | grep -o "\w" | sort | uniq -c
相关文章推荐
- 一个关于if else容易迷惑的问题
- Shell 脚本编程陷阱
- VBS脚本写的Windows硬件检测工具分享
- 用vbscript实现隐藏任务栏图标的脚本
- 用autoit编写第一个脚本(Hello World)
- VBS调用WMI快速关闭IE的脚本
- Oracle数据库执行脚本常用命令小结
- 收集的ROS防火墙脚本
- JSP脚本漏洞面面观
- 不错的批处理脚本 第一部分
- VBS脚本加密/解密VBS脚本(简易免杀版1.1)
- 不错的批处理脚本实例代码 第二部分
- 使用脚本和批处理清除电脑中的痕迹的代码第1/2页
- 让你的脚本说话
- Lua脚本获取喜马拉雅MP3音频地址
- SQL Server中数据行批量插入脚本的存储实现
- 一道sql面试题附答案
- 编程界主流脚本编程语言的比较和选择
- 批量文件查找替换功能的vbs脚本