apache日志分析工具(shell版)

没事儿练手用的东西,以后会继续优化一些功能




#!/bin/bash

LANG=en_US.UTF-8

logdir=/home/backup/weblog

#定义log文件夹

#/usr/bin/du -a $logdir

#递归显示log文件夹下所有日志文件

echo 1:查看访问量最大的十个url

echo 2:查看当前apache服务器并发连接数

echo 3:查看当前80端口连接数

echo 4:查看访问量最大的十个IP

echo 5:查看404页面url及统计

echo

read -p "1~5:" gongneng


if [ $gongneng = 1 ]

then

/usr/bin/du -a $logdir

read -p  "select a log file:" log

#读取出要查询的日志

cat  $log |awk '{print $7}' |sort|uniq -c|sort -nr|head -n 10

#检测访问量最大的十个url

elif [ $gongneng = 2 ]

then

ps -ef|grep httpd | wc -l

elif [ $gongneng = 3 ]

then

netstat -tan | grep “ESTABLISHED” | grep “:80″ | wc -l

elif [ $gongneng = 4 ]

then

/usr/bin/du -a $logdir

read -p "select a log file:" log

cat $log | awk '{print $3}'|sort |uniq -c|sort -nr|head

elif [ $gongneng = 5 ]

then

/usr/bin/du -a $logdir

read -p "select a log file:" log

cat $log | awk '{print $7,$9}'|grep 404|uniq -c

#else

echo no select

fi


你可能感兴趣的:(shell,日志分析,awk,apache日志)