教程集 www.jiaochengji.com
教程集 >  脚本编程  >  shell  >  正文 精准清除Squid缓存的shell脚本

精准清除Squid缓存的shell脚本

发布时间:2014-11-20   编辑:jiaochengji.com
本文介绍下,可以精准清除squid缓存的一个shell脚本,有需要的朋友参考。

此脚本在之前的基础上有修改,增加了if选项,并根据$1参数类型来选择性的列出缓存文件所在地址(因为$1并不固定,有时是特定的jpg类型,有时是域名)。
在Squid缓存服务器上应用的很好,特些分享给大家。

脚本内容:
 

复制代码 代码示例:
#!/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

您可能感兴趣的文章:
精准清除Squid缓存的shell脚本
squid3.x透明代理配置详解
清除代理服务器squid上的cache记录
squid2.5配置详解+认证
squid反向代理配置(web服务器的前端内容缓存器)
squid2.5安装与配置详解
awk中让人头疼的system()函数
决定squid反向代理的性能要素
squid代理配置一例
RHEL5配置Squid透明代理服务器过程解析

[关闭]
~ ~