其他分享
首页 > 其他分享> > web服务器错误日志截取及各类代码统计

web服务器错误日志截取及各类代码统计

作者:互联网

/bin/sh

    #*********************
    # get url error log
    #*********************

    curday=`date '+%Y-%m-%d %H:%M:%S'` 
    echo "input log file dir!"
    read logdir
    Code=`awk -F '[ "]+' '{print $all}' $logdir|grep 'GET'|grep '500'`
    echo "Do you want to do $1 out "Web_Code" count ? (y/n) (default: n) __"
    read do
    do=${do:=n}
    if [ "$do" = "y" ];then
    echo "Out put web code in "/home/count.log" file!\n"
    error_501=$(awk -F '[ " ]' '{print $all}' $logdir|grep "501"|wc -l)
    echo "$curday:URL error_501 count:$error_501" >>/home/count.log
    error_500=$(awk -F '[ " ]' '{print $all}' $logdir|grep "500"|wc -l)
    echo "$curday:URL error_500 count:$error_500" >>/home/count.log
    error_404=$(awk -F '[ " ]' '{print $all}' $logdir|grep "404"|wc -l)
    echo "$curday:URL error_404 count:$error_404" >>/home/count.log
    error_403=$(awk -F '[ " ]' '{print $all}' $logdir|grep "403"|wc -l)
    echo "$curday:URL error_403 count:$error_403" >>/home/count.log
    error_400=$(awk -F '[ " ]' '{print $all}' $logdir|grep "400"|wc -l)
    echo "$curday:URL error_400 count:$error_400" >>/home/count.log
    ok_200=$(awk -F '[ " ]' '{print $all}' $logdir|grep "200"|wc -l)
    echo "$curday:URL OK_200 count:$ok_200" >>/home/count.log
    fi  
    echo $Code >>/home/error.log 
    sleep 2
    echo "exit"
    exit 0

标签:count,web,log,截取,echo,logdir,error,home,日志
来源: https://www.cnblogs.com/MeiCheng/p/10668993.html