Created
October 6, 2018 18:53
-
-
Save rkorotaev/91e5ff67caa23a1af1e12888a0b89eab to your computer and use it in GitHub Desktop.
Получаем письма из Amazon S3 (от Amazon SES)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BUCKET=my-mail-bucket | |
# export AWS_PROFILE=my-aws-profile | |
# Используем стандартные утилиты из репозитория | |
DOS2UNIX="/usr/bin/dos2unix" # перенос строки | |
FORMAIL="/usr/bin/formail" # mbox-формат | |
PROCMAIL="/usr/bin/procmail" # сортировка | |
# Проходим циклом по каждому объекту в бакете | |
for F in $(aws s3 ls "s3://$BUCKET/" | awk '{print $4}'); do | |
# Получаем объект, преобразуем и передаем procmail | |
if ! aws s3 cp "s3://$BUCKET/$F" - | $DOS2UNIX | $FORMAIL | $PROCMAIL; then | |
echo "S3->Procmail fetch of $F failed with status $?" | |
else | |
echo "$0 successfully fetched $F" >> "$HOME/fetch.log" | |
# Если всё хорошо, то удаляем объект | |
aws s3 rm "s3://$BUCKET/$F" --quiet | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment