手机
当前位置:查字典教程网 >脚本专栏 >perl >服务器自动删除文件的脚本
服务器自动删除文件的脚本
摘要:支持匹配路径匹配文件名多久没有访问的自动清理复制代码代码如下:#用于各系统清理文件脚本,filepathreg_filenamefileat...

支持匹配路径 匹配文件名 多久没有访问的自动清理

复制代码 代码如下:

#用于各系统清理文件脚本,filepath reg_filename fileatime

#author Foyon0806@gmail.com

#date 2013-8-22 14:51:52

#!/bin/sh

if [ $# -eq 0 ];then

echo "Usage: sh auto_clear_file.sh clear_filepath clear_regfilename filecreatetime"

echo "eg: sh auto_clear_file.sh /tmp/log/ user_log -7day"

exit

fi

filepath=$1

regfilename=$2

if [ "-$3" = "-" ];then

filectime=`date -d -7day '+ %s'`

else

filectime=`date -d $3 '+ %s'`

fi

log=`ls $filepath | grep $regfilename`

echo $log

for file in ${log}

do

echo $file

fileatime=`stat -c %X ${filepath}${file}`

if [ ${fileatime} -lt ${filectime} ]; then

opt=`rm -f ${filepath}${file}`

echo $opt

fi

done

【服务器自动删除文件的脚本】相关文章:

perl中heredoc使用说明

PERL 正则表达式详细说明

perl实现blog备份的脚本代码

perl处理xml的模块介绍

perl 模式匹配参数详解

perl处理csv文件的小例子

使用Perl创建指定编码格式(如utf-8)文件的实现代码

perl中使用signal(信号)实例

perl中my与our的区别介绍

Perl中的子程序学习笔记

精品推荐
分类导航