I have aws cli installed. I just don't know how to do this in a shell script.
when i run aws s3 ls s3://bucket , it will give me something like this
When a ListObjects operation was called, a client error (NoSuchBucket) occurred: the specified bucket does not exist
This means that the bucket does not exist. So I want to run this from a shell script and check if grep found. But my team is not working.
if [ $(aws s3 ls "s3://$S3_BUCKET" | grep 'NoSuchBucket' &> /dev/null) == 0 ] then echo "$S3_BUCKET doesn\'t exist please check again" exit fi
He just gave it to me
backup.sh: 20: [: 0: unexpected statement
Update
I changed the script to
echo "S3_BUCKET=$S3_BUCKET" if aws s3 ls "s3://$S3_BUCKET" | grep -q 'AllAccessDisabled' then echo "$S3_BUCKET doesn\'t exist please check again" exit fi
And this is the result that I got
A client error (AllAccessDisabled) occurred when calling the ListObjects operation: All access to this object has been disabled
So the text contains AllAccessDisabled , but I'm still not echo in the next line.
source share