在指定时间内不停刷新目录下文件的时间戳
发布时间:2020-12-15 07:10:20 所属栏目:安全 来源:网络整理
导读:今天PHP站长网 52php.cn把收集自互联网的代码分享给大家,仅供参考。 #!/bin/sh#Usage : run script under certain directory,to keep files under this directory fresh#Example: nohup keepAlive 1.5#Note: directory s
以下代码由PHP站长网 52php.cn收集自互联网 现在PHP站长网小编把它分享给大家,仅供参考 #!/bin/sh #Usage : run script under certain directory,to keep files under this directory fresh #Example: nohup keepAlive 1.5& #Note: directory should have permission to write files under current directory #Visit given directory recursively and use touch command to update the timestamp of all files in it function freshDir() { for file in `ls $1` do touch $1"/"$file if [ -d $1"/"$file ] then freshDir $1"/"$file fi done } #Show help when script started without arguments function showHelp() { echo "Run script under certain directory,to keep files under this directory up to date and not be deleted" echo "Example: nohup ~yantang/tools/keepAlive 1.5&" echo "Then all files under current directory will be refreshed in the next 1.5 days " echo "Kill it manually when you no longer need it" } if [ $# -gt 0 ] then daysAlive=$1 else showHelp exit fi curDate=`date` echo "The time now: $curDate" echo "The directory will be alive for $daysAlive days" startTime=`date +%s` currentTime=$startTime typeset days=$(echo ${currentTime} ${startTime}|awk '{print ($1-$2)/86400 }') isAlive=1 while [ $isAlive -gt 0 ] do freshDir "." sleep 600 #Sleep 10 minutes currentTime=`date +%s` days=$(echo ${currentTime} ${startTime} | awk '{print ($1-$2)/86400 }') isAlive=$(echo ${days} ${daysAlive}|awk '{if($1<$2) print 1; else print 0;}') done curDate=`date` echo "Now the time is $curDate .keepAlive stopped running. Bye" 以上内容由PHP站长网【52php.cn】收集整理供大家参考研究 如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |