简单清除前端缓存脚本

环境一:nginx作为CDN前端缓存,清除各地区缓存机上所有域名下的图片文件缓存

脚本:clear.sh

#!/bin/sh 
#---CDN cache host list--- 
cat >>/tmp/iplist.txt </dev/null 
 if [ $? -eq 0 ] 
  then 
    scp /tmp/nginx-clear.sh root@$ip:/tmp 
    ssh $ip "sh  /tmp/nginx-clear.sh &&rm -f /tmp/nginx-clear.sh" 
  else 
     echo "$ip host is not exist or network is no connect,continue next host...." 
  fi 
done


引用的脚本nginx-clear.sh

 
  
#!/bin/sh 
#-----clear jpg type cache---- 
cache_path="/data/proxy_cache_dir"
grep -a -r jpg $cache_path |strings |awk -F: '{print $3}' |sed 's/^ //g'| awk 'BEGIN{FS=OFS="/"}$1="http://"$1OFS"purge"' >>/tmp/cachelist.txt 
localip= `ifconfig eth0|awk -F'[ |:]+' '/inet addr/{print $4}'` 
cat >>/etc/hosts < 
  

环境二:清除指定域名和目录路径下的缓存

 
  
#!/bin/bash 
#---source host take out the directory path 
for each in /var/wwwroot/imgtu.xxx.net/web/uploads/content/201303/*/* 
do  
  echo "$each" >>/tmp/test0417 
done 
#!/bin/bash 
#----------clean cache script---------- 
cat >>/tmp/iplist.txt <>/etc/hosts 
 for i in $URL 
 curl $i 
 done 
done