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
The Docker images we usually build are usually la...
I always feel that designers are the most sensiti...
* address - address * blockquote - block quote * c...
You know that without it, the browser will use qui...
Record some of the processes of using node-media-...
Aggregating data from various sources allows the ...
Effect: CSS style: <style type="text/css&...
1. Command Introduction time is used to count the...
1. Download the axios plugin cnpm install axios -...
In fact, we wonder every day when IE6 will really...
What problems does MySQL ROLE solve? If you are a...
Under the instructions of my leader, I took over ...
Use the following terminal command to install the...
Table of contents Using slots in Vue: slot Scoped...