Shell + crontab for log compression archiving

Source: Internet
Author: User

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

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.