Shell练习(一)
2018-02-07 10:05
176 查看
习题1:每天生成一个文件
要求:请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为)2018-02-05.log, 并且把磁盘的使用情况写到到这个文件中(不用考虑cron,仅仅写脚本即可)
参考答案:
习题2:统计日志
要求:统计出每个ip的访问量有多少?
日志1.log片段:
112.111.12.248 - [25/Sep/2013:16:08:31 +0800]formula-x.haotui.com “/seccode.php?update=0.5598″ 200″http://formula-x.haotui.com/registerbbs.php” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;)”
61.147.76.51 - [25/Sep/2013:16:08:31 +0800]xyzdiy.5d6d.com “/attach.php?aid=54&k=9c1&t=18&fid=9&sid=z1″ 301″http://xy.5d.com/thread-1435-1-23.html” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)”
参考答案:
要求:请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例如今天生成的文件为)2018-02-05.log, 并且把磁盘的使用情况写到到这个文件中(不用考虑cron,仅仅写脚本即可)
参考答案:
#!/bin/bash # date:2018年2月5日 d=`date +%F` logname="$d.log" df -h > /tmp/$logname
习题2:统计日志
要求:统计出每个ip的访问量有多少?
日志1.log片段:
112.111.12.248 - [25/Sep/2013:16:08:31 +0800]formula-x.haotui.com “/seccode.php?update=0.5598″ 200″http://formula-x.haotui.com/registerbbs.php” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1;)”
61.147.76.51 - [25/Sep/2013:16:08:31 +0800]xyzdiy.5d6d.com “/attach.php?aid=54&k=9c1&t=18&fid=9&sid=z1″ 301″http://xy.5d.com/thread-1435-1-23.html” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)”
参考答案:
awk '{print $1}' 1.log| sort -n|uniq -c|sort -n
相关文章推荐
- shell练习(1)--检测硬盘使用情况
- 每日一道shell练习(06)——检测端口服务
- 网络版shell之网络编程练习篇--telnet服务端
- Shell练习-统计出每个IP的访问量有多少?
- 【Linux】Shell - 脚本练习 - 获取文件某行的内容
- shell脚本练习:判断某IP段主机在线情况
- Shell练习(四)
- 简单的shell脚本练习(一)
- Linux常用Shell脚本练习
- 练习 3:Bash:Shell、.profile、.bashrc、.bash_history。
- shell练习1
- 【Linux】Shell - 脚本练习 - 截取文件内容
- shell练习-----猜数值
- shell练习--用户下载交互检测
- shell 练习
- shell 脚本练习4
- 【shell脚本练习】判断目录读写权限
- shell练习(2)--awk统计ip访问量(一条命令)
- shell脚本练习(autocert)
- shell命令小练习,显示日期时间及一句话