2017/11/10 shell练习;

2017/11/10

一、需求:
请按照这样的日期格式(xxxx-xx-xx)每日生成一个文件,例现在天生成的文件为)2017-07-05.log, 而且把磁盘的使用状况写到到这个文件中;php

[root@Dasoncheng sbin]# cat a.sh 
#!/bin/bash 
d=`date +%F`
logfile=$d.log
df -h >/var/dflog/$logfile
[root@Dasoncheng sbin]# crontab -l
0 10 * * * /bin/sh /usr/local/sbin/a.sh

二、需求:
要求: 统计出每一个IP的访问量有多少?
有日志1.log,内容以下:
日志片断:html

112.111.12.248 – [25/Sep/2013:16:08:31 +0800]formula-x.haotui.com “/seccode.php?update=0.5593110133088248″ 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 “/attachment.php?aid=4554&k=9ce51e2c376bc861603c7689d97c04a1&t=1334564048&fid=9&sid=zgohwYoLZq2qPW233ZIRsJiUeu22XqE8f49jY9mouRSoE71″ 301″http://xyzdiy.5d6d.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)”
[root@Dasoncheng sbin]# cat 1.log 
112.111.12.248 – [25/Sep/2013:16:08:31 +0800]formula-x.haotui.com “/seccode.php?update=0.5593110133088248″ 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 “/attachment.php?aid=4554&k=9ce51e2c376bc861603c7689d97c04a1&t=1334564048&fid=9&sid=zgohwYoLZq2qPW233ZIRsJiUeu22XqE8f49jY9mouRSoE71″ 301″http://xyzdiy.5d6d.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)”
[root@Dasoncheng sbin]# grep -v "^$" 1.log |awk '{print $1}' |sort -n|uniq -c
      1 61.147.76.51
      1 112.111.12.248

参考答案:

一、bash

#! /bin/bash
d=`date +%F`
logfile=$d.log
df -h > $logfile

二、ui

awk ‘{print $1}’ 1.log |sort -n|uniq -c |sort -n}’ 1.log |sort -n|uniq -c |sort -n  
参考答案,貌似有问题;
相关文章
相关标签/搜索