如何解决“严重错误:调用HeadObject操作时发生错误(404):键“ ...”不存在“

时间:2019-05-28 00:26:30

标签: amazon-s3

我正在尝试使用Bash脚本下载NOAA GOES数据。它可以在同事的计算机上工作,但不能在我的计算机上工作。即使文件确实存在于S3存储桶(这是任何人都可以从中下载的公共存储桶)中,我仍然遇到“致命错误”。当我在提示符下输入aws s3命令时,我可以下载文件而没有问题,但是不能让他们使用文本文件和遍历文件条目的代码来进行下载。有谁知道会导致HeadObject错误的其他原因?

我已经检查过拼写错误和操纵正斜线,但似乎没有什么错。我可以在命令提示符下手动下载文件,但是在遍历文件变量时却不能。

#!/bin/bash

#Purpose: Pulls GOES16 Full Disk data from Amazon Web Services S3 bucket
#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!#!   


           ##############################################################################
# Clean files from previous script run

rm DesiredData.txt
rm FullList.txt
echo "Please be patient. Script is reading available GOES-16 files for today from AWS bucket."

获取当前日期

DAYS=`date +%j`
YEARS=`date +%Y`

CHANNELS

CHANNELS='C01 C02 C03'

ABI产品

PRODUCTS='L1b-RadF'

获取当前日期可用的远程文件列表,并将列表发送到文本文件

for PRODUCT in $PRODUCTS; do
for YEAR in $YEARS; do
for DAY in $DAYS; do
aws s3 ls --recursive noaa-goes16/ABI-$PRODUCT/$YEAR/$DAY/ | awk '{print $3";"$4}' >> FullList.txt
done
done
done 

从上面的输出文本文件中为频道1-3的数据创建新列表

for CHANNEL in $CHANNELS; do
grep "$CHANNEL"_G16_s"$YEAR$DAY"[0-9][0-9][0][0] FullList.txt >>     DesiredData.txt
done

从DesiredData.txt列表中下载文件

for x in $(cat DesiredData.txt);
do
SIZE=$(echo $x | cut -d";" -f1)
FULLNAME=$(echo $x | cut -d";" -f2)
NAME=$(echo $x | cut -d"/" -f5)
echo "Processing file $FULLNAME"

if [ -f $NAME ]; then
    echo "This file exists locally"
    LOCALSIZE=$(du -sb $NAME | awk '{ print $1 }')
    if [ $LOCALSIZE -ne $SIZE ]; then
        echo "The size of the file is not the same as the remote file. Downloading again..."
    aws s3 cp s3://noaa-goes16/"$FULLNAME" ./
    else
    echo "The size of the file matches the remote file. Not downloading it again."
    fi
    else
    echo "This file does not exist locally, downloading..."
    aws s3 cp s3://noaa-goes16/"$FULLNAME" ./
fi

done

当我运行此代码时,到达下载部分时得到以下信息:致命错误:调用HeadObject操作时发生错误(404):键“ ABI-L1b-RadF / 2019/147/00 / OR_ABI-L1b-RadF-M6C01_G16 _...“不存在'

0 个答案:

没有答案