#! /bin/bash
path=`cd $(dirname $0);pwd -P`
cd $path
ak="Lxxxxxxxxxx" #阿里云AccessKey ID
sk="lxxxxxxxxxxxx&" #阿里云Access Key Secret 后面多个 &
dateValue=$(date '+%Y-%m-%dT%TZ')
yymmdd=$(echo $dateValue | awk -F "T" '{printf $1}')
ver=2018-05-10
timez=`date -u +"%Y-%m-%dT%H:%M:%SZ"`
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
#将current转换为时间戳,精确到毫秒
currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000))
randtime=$currentTimeStamp
if [ ! -n "$randtime" ]; then
randtime=$(tr -dc "0-9" < /dev/urandom | head -c 10)
fi
##############################
#hash签名使用
urlencode1() {
local length="${#1}"
i=0
out=""
for i in $(awk "BEGIN { for ( i=0; i<$length; i++ ) { print i; } }")
do
local c="${1:$i:1}"
case $c in
[a-zA-Z0-9.~'&'=_-]) out="$out$c" ;;
*) out="$out`printf '%%%02X' "'$c"`" ;;
esac
i=$(($i + 1))
done
echo -n $out
}
urlencode2() {
local length="${#1}"
i=0
out=""
for i in $(awk "BEGIN { for ( i=0; i<$length; i++ ) { print i; } }")
do
local c="${1:$i:1}"
case $c in
[a-zA-Z0-9.~_-]) out="$out$c" ;;
*) out="$out`printf '%%%02X' "'$c"`" ;;
esac
i=$(($i + 1))
done
echo -n $out
}
##############################
#函数
send_request() {
args="AccessKeyId=$ak&Action=$1&Format=json&$2&SignatureMethod=HMAC-SHA1&SignatureNonce=$randtime&SignatureVersion=1.0&Timestamp=$timez&Version=$ver"
StringToSign1="$(urlencode1 $args)"
StringToSign2="GET&%2F&$(urlencode2 $StringToSign1)"
hash=$(urlencode2 $(echo -n "$StringToSign2" | openssl dgst -sha1 -hmac $sk -binary | openssl base64))
RESULT=$(curl -k -s "https://cdn.aliyuncs.com/?$args&Signature=$hash") ## 2> /dev/null)
echo $RESULT
}
update() {
echo `send_request "RefreshObjectCaches" "ObjectPath=$1&ObjectType=$2"`
}
isfile=$2
if [ $isfile == 'd' ];then
update $1 Directory
else
update $1 File
fi
保存为refresh.sh
调用:./refresh.sh https:/ww.mscto.com/ f
参数f 代表文件 ;d代表目录