怎样做 网站的快捷链接网络广告营销典型案例
为了保证服务器磁盘的空间不会持续上涨,需要定期清理磁盘中的过期图片文件,具体步骤分为两步:
1、创建shell脚本:
#!/bin/bash
echo "========The script excute begin========"
baseFolder="/apps/tomcat8080/apache-tomcat-8.0.45/webapps/abnormalImg/"
year=$(date +%Y)
month=`date +%m`
monthStr=${month:0:1}
if [ $monthStr -eq "0" ];thenmonth1=${month#*0}
elsemonth1=$month
fi
month2=`expr $month1 - 2`
cd $baseFolder
for dir in $(ls $baseFolder)
doif [ -d $dir ];thenif [ $dir != $year ];thenecho "The folder "$dir" will be removed"rm -rf $direlse folder=$baseFolder$year"/"fifi
done
cd $folder
for dir1 in $(ls $folder)
doif [ -d $dir1 ];thenif [ $dir1 -lt $month2 ];thenecho "The folder "$dir1" will be removed"rm -rf $dir1fifi
done
echo "========The script excute end========"
上面这个脚本的大概意思是:获取当年的年份 year,当月的月份 month ;然后遍历图片文件夹中所有目录,判断是不是小于当月的前三个月,如果是就直接 rm -rf 删除掉,如果不是则保留;
2、创建crontab 定时任务:
输入 crontab -e 进入定时任务创建模式,然后编写下面的定时任务:意思是每天早上8:10执行指定目录下面的指定.sh脚本文件(这里指的就是第一步中创建的定时删除文件的脚本文件 test_delete.sh):
10 8 * * * /apps/tomcat8080/apache-tomcat-8.0.45/webapps/test_delete.sh;