批量清除nginx緩存簡單腳本

簡單清除前端緩存腳本前端

環境一:nginx做爲CDN前端緩存,清除各地區緩存機上全部域名下的圖片文件緩存nginx

腳本:clear.shweb

#!/bin/sh 
#---CDN cache host list--- 
cat >>/tmp/iplist.txt <<EOF
61.x.x.x 
45.x.x.x 
122.x.x.x 
EOF 
#---purge cache script send to all CDN server--- 
for ip in `cat /tmp/iplist.txt` 
do 
  ping -w 1 -c 1 $ip >/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 <<EOF
$localip imgtu.aa.net 
$localip imgtu.bb.com 
$localip imgtu.cc.com 
$localip imgtu.dd.com 
EOF 
for url in `cat  /tmp/cachelist.txt` 
do 
  curl $url 
  if [ $? -eq 0 ] 
  then 
    echo "$url is not clean,failure,please check......" 
  fi 
done

環境二:清除指定域名和目錄路徑下的緩存bash

 
 
#!/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 <<EOF
61.x.x.x 
45.x.x.x 
122.x.x.x 
EOF 
echo "please input you need clean domainname:" 
read domainname                                                                  
URL=`cat /tmp/test0417 |sed 's:/var/wwwroot/:http\://:g' |sed 's:/web:\:81/purge:g'` 
for host in `cat /tmp/iplist.txt` 
do 
 echo "$host $domainname" >>/etc/hosts 
 for i in $URL 
 curl $i 
 done 
done
相關文章
相關標籤/搜索