您的位置:首页 > 运维架构 > Shell

Shell练习(一)

2018-02-07 10:05 176 查看
习题1:每天生成一个文件
要求:请按照这样的日期格式(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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux shell