Here is a real practice: House keep log files which have been out of date for N days.
if [ $# -ne 2 ];then
echo "Usage: $0 [develop|uat|prod] [ N days ago ]"
exit -1
fi
ENV=$1
N_DAYS_AGO=$2
function getDays {
_thisMon=$1
_thisYear=`date +%Y`
_div4=`expr $_thisYear \% 4`
_div100=`expr $_thisYear \% 100`
_div400=`expr $_thisYear \% 400`
if [ $_thisMon -eq 2 ];then
if [ $_div4 -eq 0 -a $_div100 -ne 0 -a $_div400 -ne 0 ];then
echo 28
else
echo 29
fi
elif [ $_thisMon -eq 2 -O $_thisMon -eq 4 -o $_thisMon -eq 6 -o $_thisMon -eq 9 -o $_thisMon -eq 11 ];then
echo 30
else
echo 31
fi
}
logFolder="/script/logs"
TMP_FILE=.house_keep_log.tmp
#`date +%m`
THIS_YEAR=`date +%Y`
THIS_MONTH=`date +%m`
THIS_DAY=`date +%d`
DUE_YEAR=$THIS_YEAR
DUE_MONTH=$THIS_MONTH
DUE_DAY=$THIS_DAY
if [ $THIS_DAY -gt $N_DAYS_AGO ];then
DUE_DAY=`expr $THIS_DAY - $N_DAYS_AGO`
else
_TMP=`expr $N_DAYS_AGO - $THIS_DAY`
LAST_MONTH=`expr $THIS_MONTH - 1`
if [ $LAST_MONTH -eq 0 ];then
LAST_MONTH=12
DUE_YEAR=`expr $THIS_YEAR -1`
fi
LAST_MONTH_DAYS=`getDays $LAST_MONTH`
if [ $_TMP -gt $LAST_MONTH_DAYS ];then
echo "Can NOT accept $N_DAYS_AGO as 'N days ago' parameter!"
exit -1
fi
DUE_MONTH=$LAST_MONTH
DUE_DAY=`expr $LAST_MONTH_DAYS - $_TMP`
if [ $DUE_MONTH -lt 10 ];then
DUE_MONTH="0"${DUE_MONTH}
fi
fi
echo "The date of today is :$THIS_YEAR-$THIS_MONTH-$THIS_DAY"
echo "The date of $N_DAYS_AGO days ago is :$DUE_YEAR-$DUE_MONTH-$DUE_DAY"
cd $logFolder
touch -t "${DUE_YEAR}${DUE_MONTH}${DUE_DAY}0000" $TMP_FILE
for log in *.log
do
ls -l $log
if [ $log -ot $TMP_FILE ];then
#log is before FILE_B
echo "Delete $log"
rm -f $log
fi
done
rm -f $TMP_FILE
分享到:
相关推荐
主要介绍了解决ubuntu vps安装docker时报错:Cannot connect to the Docker daemon at unix:///var/run/docker.sock.问题的相关资料,文中介绍非常详细,需要的朋友可以参考借鉴,下面来一起看看吧。
The Art Of Unix Programming
UNIX, Third Edition 版本: The Textbook 3rd Edition By 作者: Syed Mansoor Sarwar – Robert M. Koretsky ISBN-10 书号: 1482233584 ISBN-13 书号: 9781482233582 Edition 版本: 3 出版日期: 2016-11-04 pages ...
UNIX : A Hacking Tutorial
本书主要介绍了Unix系统领域中的设计和开发哲学、思想文化体系、原则与经验,由公认的Unix编程大师、开源运动领袖人物之一Eric S. Raymond倾力多年写作而成。包括Unix设计者在内的多位领域专家也为本书贡献了宝贵的...
The Art of UNIX Program UNIX编程艺术 经典
2.1 UNIX操作系统的体系结构 2.2 系统概念介绍 2.2.1 文件子系统概貌 .2.2.2 进程 2.3 内核数据结构 2.4 系统管理 2.5 本章小结 2.6 习题 第3章 数据缓冲区高速缓冲 3.1 缓冲头部 3.2 缓冲池的结构 3.3 ...
The design of unix operating system. unix操作系统设计文字版
Learning the Unix Operating System is a handy book for someone just starting with Unix or Linux, and it's an ideal primer for Mac and PC users of the Internet who need to know a little about Unix on ...
Writing better software: 30 years of UNIX development wisdom In this book, five years in the making, the author encapsulates three decades of unwritten, hard-won software engineering wisdom....
我安装的子系统是Ubuntu 1804,安装docker步骤如下: sudo apt update // 更新软件源 sudo apt install -y docker.io // 安装docker sudo usermod -aG docker leo // 添加当前用户leo到docker用户组,然后重启WSL,...
The Art of Unix Programming.pdf
Amazon上五星的绝世好书!参考链接: http://www.amazon.com/UNIX-Internals-Frontiers-Uresh-Vahalia/dp/0131019082
Your UNIX/Linux: The Ultimate Guide, written with both users and programmers in mind, is the ultimate UNIX/Linux text. Both pedagogical tool and exhaustive reference, it is well-suited to any course ...
[计算机科学经典著作].The.Design.Of.The.Unix.Operating.System.part3
主要介绍了nginx connect() to unix:/var/run/php-fpm.sock failed (11: Resource temporarily unavailable),需要的朋友可以参考下
The Art of UNIX Programming-Addison-Wesley Professional (2003)作者Eric S. Raymond,epub电子书版