linux shell整理日志让awstats分析linux操作系统 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

    今天公司要对网站使用awstats来进行分析日志,并且要求把前一天的日志整进去进行分析,看了下路径和日志的位置,就有了下面的脚本.

    系统:centos 5.x

    脚本内容:

代码如下复制代码#!/bin/bash

    file1=/var/log/nginx

    file2=/tmp/robeacc/log

    find=`find $file2 -name access.log|wc -l`

    if [[ $find = 1 ]];then

    rm -f $file2/*

    fi

    ls=`ls -1t $file1/w*.ro*.ac*.gz |head -1 `

    cp -a $ls $file2/

    gunzip $file2/*

    file3=`ls -1t $file2`

    mv $file2/$file3 $file2/access.log

    这里就不截图了,大家可以自己去测试下看看.这样一整是很方便的.

    再给大家一个副产品:

代码如下复制代码#!/bin/bash

    file1=/root/log

    file2=/tmp/file

    if [ ! -d $file2 ];then

    mkdir $file2

    fi

    rm -f $file2/*

    cp -a $file1/* $file2/

    gunzip $file2/*

    for i in $file2/*;do ls --full-time $i |awk '{print $6}'|awk -F - '{print $1,$2,$3}' >>/root/1.txt;done

    sed 's/ //g' /root/1.txt>/root/t.txt

    rm -f 1.txt

    for i in `cat t.txt`;do mkdir /tmp/$i;done

    上面这个脚本可以根据日志的时间创建对应的文件夹,如图

   

    原文转自:http://blog.slogra.com/post-535.html 感谢站长

最新文章