在文件中使用时间戳:
DELAY_FOLDER='myTempFolder/'
DELAY=$((24*60*60)) # one day
while read num email limit orders; do
echo "Sending mail to '$email'"
if [[ -f $DELAY_FOLDER/$email ]] && (( $(cat "$DELAY_FOLDER/$email") + DELAY > $(date +%s) )); then
echo "email has been sent already"
else
printf "$email_template" "$email" "$num" "$limit" "$orders" | sendmail -oi -t
echo "$(date +%s)" > "$DELAY_FOLDER/$email"
fi
done < limit_mail.out
此外,如果您不希望任何人看到临时文件夹中的电子邮件地址,您可以使用 md5 或 sha sum 来覆盖您的地址。像这样:
DELAY_FOLDER='myTempFolder/'
DELAY=$((24*60*60)) # one day
while read num email limit orders; do
echo "Sending mail to '$email'"
emailsha=$(sha256sum <<< "$email" | cut -d' ' -f1)
if [[ -f $DELAY_FOLDER/$emailsha ]] && (( $(cat "$DELAY_FOLDER/$emailsha") + DELAY > $(date +%s) )); then
echo "email has been sent already"
else
printf "$email_template" "$email" "$num" "$limit" "$orders" | sendmail -oi -t
echo "$(date +%s)" > "$DELAY_FOLDER/$emailsha"
fi
done < limit_mail.out