diff --git a/scripts/bounce-watcher.sh b/scripts/bounce-watcher.sh index 890f25a..bf25382 100644 --- a/scripts/bounce-watcher.sh +++ b/scripts/bounce-watcher.sh @@ -25,7 +25,7 @@ tail -F "$LOG" 2>/dev/null | while IFS= read -r line; do # Track queue IDs originating from campaign sender if echo "$line" | grep -q "from="; then - QID=$(echo "$line" | sed -n 's/.*postfix\/[a-z]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') + QID=$(echo "$line" | sed -n 's/.*postfix\/[^[]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') if [ -n "$QID" ]; then CAMPAIGN_QIDS[$QID]=1 fi @@ -33,7 +33,7 @@ tail -F "$LOG" 2>/dev/null | while IFS= read -r line; do # Also track from= if echo "$line" | grep -q "from="; then - QID=$(echo "$line" | sed -n 's/.*postfix\/[a-z]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') + QID=$(echo "$line" | sed -n 's/.*postfix\/[^[]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') if [ -n "$QID" ]; then CAMPAIGN_QIDS[$QID]=1 fi @@ -41,7 +41,7 @@ tail -F "$LOG" 2>/dev/null | while IFS= read -r line; do # Hard bounce: status=bounced if echo "$line" | grep -q "status=bounced"; then - QID=$(echo "$line" | sed -n 's/.*postfix\/[a-z]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') + QID=$(echo "$line" | sed -n 's/.*postfix\/[^[]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') RCPT=$(echo "$line" | sed -n 's/.*to=<\([^>]*\)>.*/\1/p') # Only report if this was a campaign email @@ -65,7 +65,7 @@ tail -F "$LOG" 2>/dev/null | while IFS= read -r line; do # Soft bounce with permanent 5xx in the response if echo "$line" | grep -q "status=deferred" && echo "$line" | grep -qE "said: 5[0-9][0-9]"; then - QID=$(echo "$line" | sed -n 's/.*postfix\/[a-z]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') + QID=$(echo "$line" | sed -n 's/.*postfix\/[^[]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') RCPT=$(echo "$line" | sed -n 's/.*to=<\([^>]*\)>.*/\1/p') if [ -n "$QID" ] && [ -n "$RCPT" ] && [ -n "${CAMPAIGN_QIDS[$QID]+x}" ]; then @@ -86,7 +86,7 @@ tail -F "$LOG" 2>/dev/null | while IFS= read -r line; do # Clean up old QIDs when they're removed from queue if echo "$line" | grep -q "removed$"; then - QID=$(echo "$line" | sed -n 's/.*postfix\/[a-z]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') + QID=$(echo "$line" | sed -n 's/.*postfix\/[^[]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') if [ -n "$QID" ]; then unset CAMPAIGN_QIDS[$QID] 2>/dev/null fi diff --git a/scripts/hc-bounce-watcher.sh b/scripts/hc-bounce-watcher.sh index 27415de..4e99a08 100644 --- a/scripts/hc-bounce-watcher.sh +++ b/scripts/hc-bounce-watcher.sh @@ -44,17 +44,17 @@ post_bounce() { tail -F "$LOG" 2>/dev/null | while IFS= read -r line; do # Track queue IDs that originate from the hc sender OR go out an hcout transport. if echo "$line" | grep -q "$HC_SENDER1"; then - QID=$(echo "$line" | sed -n 's/.*postfix\/[a-z0-9]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') + QID=$(echo "$line" | sed -n 's/.*postfix\/[^[]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') [ -n "$QID" ] && HC_QIDS[$QID]=1 fi if echo "$line" | grep -qE "postfix/hcout[123]/"; then - QID=$(echo "$line" | sed -n 's/.*postfix\/[a-z0-9]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') + QID=$(echo "$line" | sed -n 's/.*postfix\/[^[]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') [ -n "$QID" ] && HC_QIDS[$QID]=1 fi # Hard bounce if echo "$line" | grep -q "status=bounced"; then - QID=$(echo "$line" | sed -n 's/.*postfix\/[a-z0-9]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') + QID=$(echo "$line" | sed -n 's/.*postfix\/[^[]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') RCPT=$(echo "$line" | sed -n 's/.*to=<\([^>]*\)>.*/\1/p') if [ -n "$QID" ] && [ -n "$RCPT" ] && [ -n "${HC_QIDS[$QID]+x}" ]; then post_bounce "$RCPT" "hard" "$QID" @@ -64,7 +64,7 @@ tail -F "$LOG" 2>/dev/null | while IFS= read -r line; do # Soft bounce that's actually a permanent 5xx if echo "$line" | grep -q "status=deferred" && echo "$line" | grep -qE "said: 5[0-9][0-9]"; then - QID=$(echo "$line" | sed -n 's/.*postfix\/[a-z0-9]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') + QID=$(echo "$line" | sed -n 's/.*postfix\/[^[]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') RCPT=$(echo "$line" | sed -n 's/.*to=<\([^>]*\)>.*/\1/p') if [ -n "$QID" ] && [ -n "$RCPT" ] && [ -n "${HC_QIDS[$QID]+x}" ]; then post_bounce "$RCPT" "soft" "$QID" @@ -73,7 +73,7 @@ tail -F "$LOG" 2>/dev/null | while IFS= read -r line; do # Cleanup queue IDs as they leave the queue if echo "$line" | grep -q "removed$"; then - QID=$(echo "$line" | sed -n 's/.*postfix\/[a-z0-9]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') + QID=$(echo "$line" | sed -n 's/.*postfix\/[^[]*\[\([0-9]*\)\]: \([A-Z0-9]*\):.*/\2/p') [ -n "$QID" ] && unset HC_QIDS[$QID] 2>/dev/null REMOVED_COUNT=$((REMOVED_COUNT + 1)) [ $((REMOVED_COUNT % 100)) -eq 0 ] && CURRENT_UUID=$(get_campaign_uuid)