- #!/bin/bash
- cat << EOF
- ------------------------------------
- 日志分析小工具
- ------------------------------------
- EOF
- LANG=en_US
- Usage() {
- echo "Usage: $0 Logfile"
- }
- if [ $# -eq 0 ] ;then
- Usage
- exit 0
- else
- Log=$1
- fi
- Tmpfile=$(mktemp)
- Year=$(date |awk '{print $6}')
- Mon=$(date |awk '{print $2}')
- Day=$(date |awk '{print $3}')
- Yesterday=$((Day-1))
- echo -e " 33[31m-------the ${Year}-${Mon}-${Yesterday} log statistics as shown:-------- 33[0m"
- echo -e " 33[32m the UV in total yesterday: 33[0m "
- cat $Log| sed -n "/${Yesterday}/${Mon}/${Year}:00/,/${Day}/${Mon}/${Year}:00/p" | awk '{print $7}'|wc -l
- echo -e " 33[32m Most of the time yesterday: 33[0m "
- cat $Log |awk '{print $4}' |cut -c 14-18 |sort|uniq -c | sort -nr | head -10
- echo -e " 33[32m Most of the page yesterday: 33[0m "
- cat $Log |sed -n "/${Yesterday}/${Mon}/${Year}:00/,/${Day}/${Mon}/${Year}:00/p" | awk '{print $11}' |sort |uniq -c |sort -rn |head -10
- echo -e " 33[32m Most of the ip yesterday: 33[0m "
- cat $Log| sed -n "/${Yesterday}/${Mon}/${Year}:00/,/${Day}/${Mon}/${Year}:00/p" | awk '{print $1}' | sort |uniq -c |sort -rn |head -10 > $Tmpfile
- cat $Tmpfile | while read line;
- do
- num=$(echo $line|awk '{print $1}')
- echo -n "访问次数:$num "
- ip=$(echo $line|awk '{print $2}')
- curl -s ip.cn?ip=$ip
- done