#!/bin/bash
# Source and destination buckets
SRC_BUCKET=""
DEST_BUCKET=""
# File with the list of keys
KEYS_FILE="task.txt"
# Read file line by line
while read -r line
do
# Check if object exists in the destination bucket
if aws s3api head-object --bucket "$DEST_BUCKET" --key "$line" > /dev/null 2>&1
then
echo "Object $line already exists in the destination bucket, skipping."
else
# Copy object to destination bucket
echo "Copying object $line to destination bucket."
aws s3 cp "s3://$SRC_BUCKET/$line" "s3://$DEST_BUCKET/$line"
fi
done < "$KEYS_FILE"