为了避免每次前端需要刷新缓存 登陆网宿 选择内容管理 的操作。打算写成shell  通过传入url 实现cdn刷新。

 

思路执行脚本t.1.sh ,复制cache_dirs_base.sh 为临时脚本cache_dirs_tmp.sh,执行完毕可以自删除或者手动删除,替换脚本里需要清理缓存的url或者dir,执行调用清除缓存的脚本cache_dirs_tmp.sh 。

 

t.1.sh如下

#!/bin/bash

# @Time    : 2019-12-17

# @Author  : jiaminxu

# @Description  : 清理网宿缓存

 

url="$1"

cache_url=${url//\//\\\/}

echo $cache_url

yes | cp cache_dirs_base.sh cache_dirs_tmp.sh

 

sed -i "s/https:\/\/oss.aircourses.com\/newkj\/data\/acc\/l3u1c9\/thumb\//$cache_url/g" cache_dirs_tmp.sh

 

sh cache_dirs_tmp.sh

 

 

cache_dirs_base.sh如下

#!/bin/bash

# @Time    : 2019-12-17

# @Author  : jiaminxu

# @Description  : 清理网宿缓存

 

username=" username "

apiKey=" apiKey "

cache_url=$1

date=`env LANG="en_US.UTF-8" date -u "+%a, %d %b %Y %H:%M:%S GMT"`

password=`echo -en "$date" | openssl dgst -sha1 -hmac $apiKey -binary | openssl enc -base64`

curl -i --url "https://open.chinanetcenter.com/ccm/purge/ItemIdReceiver" \

-X "POST" \

-u "$username:$password" \

-H "Date:$date" \

-H "Content-Type: application/json" \

-d'{

    "dirs": [

        "https://oss.aircourses.com/newkj/data/acc/l3u1c9/thumb/"

            ]

}'

 

 

 

 

执行

shell脚本清理网宿cdn缓存

 

页面任务 显示已经执行

shell脚本清理网宿cdn缓存

 

目前是url和dir分开清理 后续看情况 合到一起

 

 

api参考

https://si.chinanetcenter.com/v2/index/#/apidoc/apiDetail?docId=889&classify=ContentManagement

 

 

 

 

 

相关文章: