当前位置: > shell编程 >

shell脚本定时清理日志的例子

时间:2014-08-20 02:49来源:linux.it.net.cn 作者:it

例子,定时清理日志文件的shell脚本代码。
 

复制代码代码示例:

#!/bin/bash
# www.jbxue.com

source ~/.bash_profile

file_base=/mstms/apms
posp_file=/mstms/POSP
filedate1=`date -d "-30 days" +%F`
filedate2=`date -d "-30 days" +%Y%m%d`

cd $file_base 
find ./ -name *"$filedate1"* -exec rm -rf {} \;
find ./ -name *"$filedate2"* -exec rm -rf {} \;
cd $posp_file
find ./ -name *"$filedate1"* -exec rm -rf {} \;
find ./ -name *"$filedate2"* -exec rm -rf {} \;
cd ~
find ./ -name *"$filedate1"* -exec rm -rf {} \;
find ./ -name *"$filedate2"* -exec rm -rf {} \;

以上shell脚本中,主要是用到了find命令的-name参数

(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容