nginx缓存管理 shell脚本批量清除nginx缓存代码

发布时间:2020-05-07编辑:脚本学堂
如何批量清除nginx缓存文件内容,用shell脚本清除nginx缓存无疑是最方便的,这里分享一例shell脚本代码,大家参考下。

shell/ target=_blank class=infotextkey>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 Insertclean Nginx cache File, Example: $0 index.html index.js"

sleep 2 && exit

fi

echo "The file : $FILEto 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}| linuxjishu/13830.html target=_blank class=infotextkey>awk -F':' '{print $1}'  > /tmp/cache_list.txt

for j in `cat/tmp/cache_list.txt`

do

rm  -rf $j

echo "$i $j is DeletedSuccess !"

done

done

#The Scripts exec success and exit 0

执行清除脚本后的截图:
<a href=http://www.jb200.com/nginx/proxy-cache/ target=_blank class=infotextkey>nginx缓存</a>管理 shell脚本批量清除nginx缓存代码