怎么用Shell脚本批量清除Nginx缓存

这篇文章主要介绍“怎么用Shell脚本批量清除Nginx缓存”,在日常操作中,相信很多人在怎么用Shell脚本批量清除Nginx缓存问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么用Shell脚本批量清除Nginx缓存”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

代码如下:


#! /bin/sh
#Auto Clean Nginx Cache Shell Scripts
#2013-06-12  wugk
#Define Path
CACHE_DIR=/data/www/proxy_cache_dir/
FILE="$*"

#To determine whether the input script,If not, then exit 判断脚本是否有输入,没有输入然后退出
if
 [  "$#" -eq "0" ];then
 echo "Please Insert clean Nginx cache File, Example: $0 index.html index.js"
 sleep 2 && exit
fi
 echo "The file : $FILE to be clean nginx Cache ,please waiting ....."

#Wrap processing for the input file, for grep lookup,对输入的文件进行换行处理,利于grep查找匹配相关内容
for i in `echo $FILE |sed 's//\n/g'`
do
  grep -ra  $i  ${CACHE_DIR}| awk -F':' '{print $1}'  > /tmp/cache_list.txt
   for j in `cat/tmp/cache_list.txt`
 do
   rm  -rf  $j
   echo "$i  $j  is  Deleted Success !"
 done
done
#The Scripts exec success and exit 0

如下为执行清除脚本后的截图:

怎么用Shell脚本批量清除Nginx缓存

到此,关于“怎么用Shell脚本批量清除Nginx缓存”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注网站,小编会继续努力为大家带来更多实用的文章!