通过获取token,对象oss创建桶名称和文件上传
#!/bin/bash #oss对象存储访问地址 sfoss_host="http://fns-css-core-shenzhen-xili1.osssit.sfcloud.local:8080/v1/AUTH_FNS-CSS-CORE/" #获取昨天日期,20230510 daysdate=`date -d "3 days ago" +%Y%m%d` #设置oss对象存储桶名称 yunhu20230510 sfoss_bucket="yunhu$daysdate" #设置oss对象存储AK AK="Rk5TLUNTUy1DT1JFOkZOUy1DU1MtQ09SRQ==" #设置oss对象存储SK SK="2e47a2f2ec5e14d4acebdebf2364b674" osshost=$host/$bucket echo $osshost #将昨天云呼系统生成的所有录音文件名称输出到文档yunhurecord20230510.txt yunhurecordpath="/usr/local/freeswitch/recordings/archive/$daysdate" ls $yunhurecordpath/*.mp3 > $yunhurecordpath/yunhurecord$daysdate.txt yunhurecordname="$yunhurecordpath/yunhurecord$daysdate.txt" #获取oss对象存储访问地址的token sfoss_token_url="http://fns-css-core-shenzhen-xili1.osssit.sfcloud.local:8080/auth/v1.0" #curl_sfoss_token=`curl -i http://fns-css-core-shenzhen-xili1.osssit.sfcloud.local:8080/auth/v1.0 -X GET \ echo $sfoss_token_url curl_sfoss_token=`curl -i ${sfoss_token_url} -X GET \ -H "X-Auth-User: ${AK}" \ -H "X-Auth-Key: ${SK}" > $yunhurecordpath/sfoss_token.txt` sfoss_token=`cat $yunhurecordpath/sfoss_token.txt|grep X-Auth-Token:|awk '{print $NF}'` echo $sfoss_token #oss对象存储创建桶名称 yunhu$daysdate #curl -i -H "X-Auth-Token: AUTH_tk14c9ca32478f56e41a2e4f4e97546ac46a563796d73df775958b4fdcf1f9ffd1074e3fc836bc7ea40cfb4608d2a9f09be9c1b2426e973877de00a8710e037dc81324b1cbefbd642a2474706580784ef9" http://fns-css-core-shenzhen-xili1.osssit.sfcloud.local:8080/v1/AUTH_FNS-CSS-CORE/yunhu20230510 -X PUT curl -i -H "X-Auth-Token: $sfoss_token" $sfoss_host$sfoss_bucket -X PUT #oss对象存储获取桶名称 yunhu$daysdate #将curl响应状态码,存放到变量%{http_code}中 #curl -s -w "%{http_code}\n" -H "X-Auth-Token: AUTH_tk14c9ca32478f56e41a2e4f4e97546ac46a563796d73df775958b4fdcf1f9ffd1074e3fc836bc7ea40cfb4608d2a9f09be9c1b2426e973877de00a8710e037dc8e79f835f6074737e7fcadf8306e941fd" http://fns-css-core-shenzhen-xili1.osssit.sfcloud.local:8080/v1/AUTH_FNS-CSS-CORE/yunhu20230510 -X GET ret_code=$(curl -s -w "%{http_code}\n" -H "X-Auth-Token: $sfoss_token" $sfoss_host$sfoss_bucket -X GET) echo ${ret_code} source="/mnt/dumpfile/test.txt" dest="dumpfiles/test.txt" resource="/${bucket}/${dest}" contentType=`file -ib ${source} |awk -F ";" '{print $1}'` dateValue="`TZ=GMT env LANG=en_US.UTF-8 date +'%a, %d %b %Y %H:%M:%S GMT'`" stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}" signature=`echo -en $stringToSign | openssl sha1 -hmac ${key} -binary | base64` url=http://${osshost}/${dest} echo "upload ${source} to ${url}" curl -i -q -X PUT -T "${source}" \ -H "Host: ${osshost}" \ -H "Date: ${dateValue}" \ -H "Content-Type: ${contentType}" \ -H "Authorization: OSS ${id}:${signature}" \ ${url}