企业面试题1:
已知下面的字符串是通过RANDOM随机数变量md5sum|cut-c 1-8截取后的结果,请破解这些字符串对应的md5sum前的RANDOM对应数字?
21029299
00205d1c
a3da1677
1f6d12dd
890684b
解题思路:通过每次传递一个参数的方式,来实现依次破解
$RANDOM的范围为0-32767
#!/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 -c
2.按字母出现频率降序排序!
解决思路:使用grep -o "\w",把单词拆开并去除种各符号
#cat c.txt | grep -o "\w" | sort | uniq -c
已知下面的字符串是通过RANDOM随机数变量md5sum|cut-c 1-8截取后的结果,请破解这些字符串对应的md5sum前的RANDOM对应数字?
21029299
00205d1c
a3da1677
1f6d12dd
890684b
解题思路:通过每次传递一个参数的方式,来实现依次破解
$RANDOM的范围为0-32767
#!/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
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 -c
2.按字母出现频率降序排序!
解决思路:使用grep -o "\w",把单词拆开并去除种各符号
#cat c.txt | grep -o "\w" | sort | uniq -c
编辑回复