此指令碼是在張宴的緩衝清理指令碼上做了修改的,主要是增加if選項,並根據$1參數類型來選擇性的列出快取檔案所在地址(因為$1並不固定,有時是特定的jpg類型,有時是網域名稱)目前在自己的Squid快取服務器上應用,感覺採集緩衝網址基本上沒什麼誤差了,歡迎大家試用,爭取將此指令碼做到更加完美(此指令碼在Centos5.4 x86_64,Squid2.7下通過)指令碼內容如下:
- #!/bin/sh
- squidcache_path="/usr/local/squid/var/cache"
- squidclient_path="/usr/local/squid/bin/squidclient"
- #grep -a -r $1 $squidcache_path/* | strings | grep "http:" | awk -F 'http:' '{print "http:"$2;}' | awk -F\' '{print $1}' > cache.txt
-
- if [[ "$1" == "swf" || "$1" == "png" || "$1" == "jpg" || "$1" == "ico" || "$1" == "gif" || "$1" == "css" || "$1" == "js" || "$1" == "html" || "$1" == "shtml" || "$1" == "htm" ]]; then
- grep -a -r .$1 $squidcache_path/* | strings | grep "http:" | awk -F 'http:' '{print "http:"$2;}' | awk -F\' '{print $1}' | grep "$1$" | uniq > cache.txt
- else
- grep -a -r $1 $squidcache_path/* | strings | grep "http:" | awk -F 'http:' '{print "http:"$2;}' | awk -F\' '{print $1}' | uniq > cache.txt
- fi
-
- cat cache.txt | while read LINE
- do
- $squidclient_path -p 80 -m PURGE $LINE
- done
本文出自 “撫琴煮酒” 部落格,請務必保留此出處http://blog.chinaunix.net/uid-12924167-id-3193164.html