原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://blog.chinaunix.net/uid-12924167-id-3193164.html

此脚本是在张宴的缓存清理脚本上做了修改的,主要是增加if选项,并根据$1参数类型来选择性的列出缓存文件所在地址(因为$1并不固定,有时是特定的jpg类型,有时是域名)目前在自己的Squid缓存服务器上应用,感觉采集缓存网址基本上没什么误差了,欢迎大家试用,争取将此脚本做到更加完美(此脚本在Centos5.4 x86_64,Squid2.7下通过)脚本内容如下:

  1. #!/bin/sh 
  2. squidcache_path="/usr/local/squid/var/cache" 
  3. squidclient_path="/usr/local/squid/bin/squidclient" 
  4. #grep -a -r $1 $squidcache_path/* | strings | grep "http:" | awk -F 'http:' '{print "http:"$2;}' |  awk -F\' '{print $1}' > cache.txt 
  5.  
  6. if [[ "$1" == "swf" || "$1" == "png" || "$1" == "jpg" || "$1" == "ico" || "$1" == "gif" || "$1" == "css" || "$1" == "js" ||  "$1" == "html" || "$1" == "shtml" || "$1" == "htm"   ]]; then 
  7.  grep -a -r .$1 $squidcache_path/* | strings | grep "http:" | awk -F 'http:' '{print "http:"$2;}' |  awk -F\' '{print $1}' | grep "$1$"  | uniq > cache.txt 
  8.  else 
  9.  grep -a -r $1  $squidcache_path/* | strings | grep "http:" | awk -F 'http:' '{print "http:"$2;}' |  awk -F\' '{print $1}' | uniq > cache.txt 
  10. fi 
  11.  
  12. cat cache.txt | while read LINE 
  13. do 
  14.   $squidclient_path -p 80 -m PURGE $LINE 
  15. done 

本文出自 “抚琴煮酒” 博客,请务必保留此出处http://blog.chinaunix.net/uid-12924167-id-3193164.html

08-29 01:54