Nginx Proxy_cache Bulk Cleanup Script

Source: Internet
Author: User

the previous use of the official Nginx Proxy_cache as a CDN static cache found that the module cleanup cache is a big problem, can only be a single URL of the cleanup, for this write a batch cleanup cache script

Main features include:

1. Cleaning by file type

2. Clean by specific filename

3. Clean by Site Directory

Here's the Bash shell script code, which is a lot of similar scripts on the web, but it's not very good and it's easy to mislead the wrong person.

#!/bin/bash #Email: hello_linux@aliyun.com #Auto clean Nginx proxy_cache Shell Scripts #Aunthor: Sun~shell #Date : 2017-02-23 echo-e "\ n" echo-n-E "\e[35;1m Please enter Nginx proxy_cache the specific path of the cache (Friendship tip: You can use the tab full function Oh!) \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;1m Please enter the action \n1 you want to delete. Delete by file type \t2. Delete \t3 by specific file name. 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 type of cache file you want to delete (you can enter multiple parameter spaces to separate) \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 '} ' >/tmp/cache_list.txt for J. ' Cat/tmp/cache_list.txt ' do rm-rf $j Echo ' $ I $j DeleteSuccess! "
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 parameter spaces to separate) \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}| a   Wk ' BEGIN {fs= ': '} {print '} ' >/tmp/cache_list.txt for J ' cat/tmp/cache_list.txt ' do rm-rf $j Echo ' $i
 $J Delete Successful! "
done;; 3) echo-e "\e[32;1m----------------------------------------------------------------\e[0m" Echo-e "\E[32; 1m----------------------------------------------------------------\e[0m "Echo-n-E" \e[33;1m supported modes are: \
N1. Clear all caches in the site Store directory: test.dd.com/data/upload/shop/store\n2. Clear all caches under the Web site shop: test.dd.com/data/upload/shop\e[0m\n Echo-n-E "\e[34;1m Please enter the specific directory of the cached files 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 $} ' >/tmp/cache_list.txt for J ' cat/tmp/cache_list.txt ' do rm-rf $j echo ' $i $j Delete success! '
done;;
*) echo "input error, please re-enter";; Esac



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.