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