Linux Shell collation log let Awstats analysis

Source: Internet
Author: User
Tags mkdir

System: CentOS 5.x
Script content:

The code is as follows Copy Code
#!/bin/bash
File1=/var/log/nginx
File2=/tmp/robeacc/log
Find= ' Find $file 2-name access.log|wc-l '
if [[$find = 1]];then
Rm-f $file 2/*
Fi
Ls= ' ls-1t $file 1/w*.ro*.ac*.gz |head-1 '
Cp-a $ls $file 2/
Gunzip $file 2/*
File3= ' ls-1t $file 2 '
MV $file 2/$file 3 $file 2/access.log


Here is not a screenshot, we can go to test the next look. Such a whole is very convenient.
And give you a byproduct:

The code is as follows Copy Code
#!/bin/bash
File1=/root/log
File2=/tmp/file
if [!-D $file 2];then
mkdir $file 2
Fi
Rm-f $file 2/*
Cp-a $file 1/* $file 2/
Gunzip $file 2/*
For i in $file 2/*;d o ls--full-time $i |awk ' {print $} ' |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 ';d o mkdir/tmp/$i;d One

The above script can create a corresponding folder based on the time of the log, as shown

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.