天天看點

用SHELL腳本精準清除Squid緩存[更新版]

此腳本是在張宴的緩存清理腳本上做了修改的,主要是增加if選項,并根據$1參數類型來選擇性的列出緩存檔案所在位址(因為$1并不固定,有時是特定的jpg類型,有時是域名)目前在自己的Squid緩存伺服器上應用,感覺采集緩存網址基本上沒什麼誤差了,歡迎大家試用,争取将此腳本做到更加完美(此腳本在Centos5.4 x86_64,Squid2.7下通過)腳本内容如下:

1

2

3

4

5

6

7

8

9

10

11

12

<code>#!/bin/sh</code>

<code>squidcache_path=</code><code>"/usr/local/squid/var/cache"</code>

<code>squidclient_path=</code><code>"/usr/local/squid/bin/squidclient"</code>

<code>if</code> <code>[[ </code><code>"$1"</code> <code>=~ swf|png|jpg|ico|gif|css|js|htm|html|shtml ]]; </code><code>then</code>

<code>grep</code> <code>-a -r .$1 $squidcache_path/* | strings | </code><code>grep</code> <code>"http:"</code> <code>| </code><code>awk</code> <code>-F </code><code>'http:'</code> <code>'{print "http:"$2;}'</code> <code>|  </code><code>awk</code> <code>-F\</code><code>' '</code><code>{print $1}' &gt; cache.txt</code>

<code>else</code>

<code>grep</code> <code>-a -r $1 $squidcache_path/* | strings | </code><code>grep</code> <code>"http:"</code> <code>| </code><code>awk</code> <code>-F </code><code>'http:'</code> <code>'{print "http:"$2;}'</code> <code>|  </code><code>awk</code> <code>-F\</code><code>' '</code><code>{print $1}' &gt; cache.txt</code>

<code>fi</code>

<code>while</code> <code>read</code> <code>LINE</code>

<code>do</code>

<code>$squidclient_path -h 122.70.148.51 -p 80 -m PURGE $LINE</code>

<code>done</code> <code>&lt; cache.txt</code>

本文轉自 撫琴煮酒 51CTO部落格,原文連結:http://blog.51cto.com/yuhongchun/838275,如需轉載請自行聯系原作者

繼續閱讀