Preface: I used the official nginx proxy_cache as CDN static cache before and found that it was a big problem to clear the cache in this module. It can only clear URLs one by one. For this reason, I wrote a script to clear the cache in batches. Key features include: 1. Clean by file type 2. Clean up by specific file name 3. Clean up by website directory The following is the bash shell script code. There are many similar scripts on the Internet before, but they are not very good and can easily mislead people to make mistakes. #!/bin/bash #Email:[email protected] #Auto Clean Nginx Proxy_Cache Shell Scripts #Aunthor:sun~shell #Date:2017-02-23 echo -e "\n\n" echo -n -e "\e[35;1mPlease enter the specific path of Nginx Proxy_cache cache (Friendly reminder: You can use the Tab completion function!)\e[0m\e[34;5m:\e[0m" read -e path CACHE_DIR=$path echo -e "\e[32;1m----------------------------------------------------------------\e[0m" echo -e "\e[32;1m----------------------------------------------------------------\e[0m" echo -n -e "\e[32;1mPlease enter the action you want to delete\n1. Delete by file type\t2. Delete by specific file name\t3. Delete by file directory\n:" read action case $action in 1) echo -e "\e[32;1m----------------------------------------------------------------\e[0m" echo -e "\e[32;1m----------------------------------------------------------------\e[0m" echo -n -e "\e[34;1m Please enter the cache file type you want to delete (you can enter multiple parameters separated by spaces)\e[0m\e[34;5m:\e[0m" read -a FILE for i in `echo ${FILE[*]}|sed 's/ /\n/g'` do grep -r -a \.$i ${CACHE_DIR}| awk 'BEGIN {FS=":"} {print $1}' > /tmp/cache_list.txt for j in `cat /tmp/cache_list.txt` do rm -rf $j echo "$i $j deleted successfully!" done done ;; 2) echo -e "\e[32;1m----------------------------------------------------------------\e[0m" echo -e "\e[32;1m----------------------------------------------------------------\e[0m" echo -n -e "\e[33;1m Please enter the specific name of the cache file you want to delete (you can enter multiple parameters separated by spaces)\e[0m\e[34;5m:\e[0m" read -a FILE for i in `echo ${FILE[*]}|sed 's/ /\n/g'` do grep -r -a $i ${CACHE_DIR}| awk 'BEGIN {FS=":"} {print $1}' > /tmp/cache_list.txt for j in `cat /tmp/cache_list.txt` do rm -rf $j echo "$i $j deleted successfully!" done done ;; 3) echo -e "\e[32;1m----------------------------------------------------------------\e[0m" echo -e "\e[32;1m----------------------------------------------------------------\e[0m" echo -n -e "\e[33;1mSupported modes are:\n1. Clear all caches under the store directory of the website: test.dd.com/data/upload/shop/store\n2. Clear all caches under the shop directory of the website: test.dd.com/data/upload/shop\e[0m\n" echo -n -e "\e[34;1m Please enter the specific directory of the cache file you want to delete\e[0m\e[34;5m:\e[0m" read -a FILE for i in `echo ${FILE[*]}|sed 's/ /\n/g'` do grep -r -a "$i" ${CACHE_DIR}| awk 'BEGIN {FS=":"} {print $1}' > /tmp/cache_list.txt for j in `cat /tmp/cache_list.txt` do rm -rf $j echo "$i $j deleted successfully!" done done ;; *) echo "Input error, please re-enter" ;; esac Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: How to use VUE and Canvas to implement a Thunder Fighter typing game
>>: Tutorial on using prepare, execute and deallocate statements in MySQL
This article shares the specific code for JavaScr...
1. Modify the Linux server docker configuration f...
This article shares the specific code of jQuery t...
MySQL 5.7.18 installation and problem summary. I ...
Table of contents What are immutable values? Why ...
This article describes how to export and import ....
1. Pull the redis image docker pull redis 2. Star...
CocosCreator version: 2.3.4 Cocos does not have a...
The road ahead is long and arduous, but I will co...
Table of contents 1. Error phenomenon 2. Error An...
Table of contents Features Preservation strategy ...
1.vue packaging Here we use the vue native packag...
To put it simply, the IP of the virtual machine u...
Public name of the page: #wrapper - - The outer e...
Three ways to set borders in HTML border-width: 1...