目標:gri/使用SendToS3.shshell 腳本將檔案推送到 S3 存盤桶。
我正在關注本教程。
SendToS3.sh在 cwd 中。它需要獲取所有不在子檔案夾中的檔案,在 cwd 的gri/.
終端:
me@PF2DCSXD:/mnt/c/Users/me/Documents/GitHub/workers-python/workers/data_simulator/data$ ./SendToS3.sh
./SendToS3.sh: line 17: logInfo: command not found
curl: Can't open '/gri/*'!
curl: try 'curl --help' or 'curl --manual' for more information
curl: (26) Failed to open/read local data from file/application
./SendToS3.sh: line 27: logInfo: command not found
SendToS3.sh:
bucket=simulation
files_location=/gri/ # !
now_time=$(date "%H%M%S")
contentType="application/x-compressed-tar"
dateValue=`date -R`
# your key goes here..
s3Key= # CENSORED
# your secrets goes here..
s3Secret= # CENSORED
function pushToS3()
{
files_path=$1
for file in $files_path*
do
fname=$(basename $file)
logInfo "Start sending $fname to S3"
resource="/${bucket}/${now_date}/${fname}_${now_time}"
stringToSign="PUT\n\n${contentType}\n${dateValue}\n${resource}"
signature=`echo -en ${stringToSign} | openssl sha1 -hmac ${s3Secret} -binary | base64`
curl -X PUT -T "${file}" \
-H "Host: ${bucket}.s3.amazonaws.com" \
-H "Date: ${dateValue}" \
-H "Content-Type: ${contentType}" \
-H "Authorization: AWS ${s3Key}:${signature}" \
https://${bucket}.s3.amazonaws.com/${now_date}/${fname}_${now_time}
logInfo "$fname has been sent to S3 successfully."
done
}
pushToS3 $files_location
如果還有什么我可以添加到帖子中,請告訴我。
uj5u.com熱心網友回復:
您的系統沒有loginfo,因此可以將該命令切換為echo。為了您的卷曲的錯誤也可能是檔案權限錯誤,請嘗試運行:
chmod -rwx gri。
或者,您可以改用aws cli,這更容易使用 imo。
uj5u.com熱心網友回復:
錯誤在以下這一行。該檔案夾/gri/為空或啟動腳本的用戶無權訪問它。
卷曲:無法打開“/gri/*”!
此外,您的服務器似乎沒有LogInfo安裝可執行檔案,或者您的腳本無法訪問它SendToS3.sh。驗證安裝并將二進制檔案添加到PATHenv 變數。
./SendToS3.sh: line 17: logInfo: command not found
獎勵:curl您可以使用aws-cliwhich 來優化以與 aws 組件互動,而不是使用。請在s3此處找到檔案:https : //docs.aws.amazon.com/cli/latest/reference/s3/
例如,您可以使用以下命令將檔案復制到 w 存盤桶:
aws s3 cp <path_to_file> s3://<bucket_name>/<path>/
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/367414.html
