Shell + crontab for log compression archiving
Crontab
1 file 7 Days . 2 */5 * * * * root/bin/sh /path/archive_atslog. sh >/dev/null2>&1
Shell
1#!/bin/Bash2 # Author:standby3# Date: .-Geneva- -4# description:archive The live log, keep the lastest7Days .5 6Logdir="/data/ats/logs"7Today= 'Date-D"6 minutes ago"+%y%m%d '8 9 functionget_exter_ip ()Ten { OneArr= ('/sbin/ifconfig-a|grepInet|grep-V127.0.0.1|grep-V inet6|awk '{print $}'|TR-D"Addr:"`) Aexter_ip=${arr[0]} - forIpinch${arr[*]} - Do theIp_tmp= 'Echo$ip |grep-V'^10\.'` - if[[!-Z $ip _tmp]]; Then - Break - fi + Done -exter_ip=$ip _tmp + Echo$exter _ip A } atip=' Get_exter_ip ' -# rename Logfile - CD $logdir - forIinch`lsAccess.log_*. Old ' - Do -Date= 'Echo$i |awk-F"[-.]" '{print $ (NF-4) $ (NF-3)}'|sed 's/[hms]//g'` in MV$i Live_${ip}_${date}_05min.log - Done to +Subpath= $logdir/$TODAY/ -#gzipand archive logfile the[!-D $subPath] &&mkdir-P $subPath * forIinch`lsLive_*.*_05min.log ' $ DoPanax Notoginseng gzip$i - MV$i". GZ"$subPath the Done + A# Clean log fileswhich 7Days ago theI=0 + while[[I-lt7 ]] - Do $Weekday[i]= 'Date-D"-${i} Day"+"%y%m%d"` $Let i++ - Done - for dir inch`ls|grep-E"([0-9]{8})"` the Do -[["${weekday[@]}"=~ $dir]] ||RM-RF $dirWuyi Done
Shell + crontab for log compression archiving