Files

670 B

#!/bin/bash

# Ensure we're using Bash
if [ -z "$BASH_VERSION" ]; then
    echo "This script must be run with Bash."
    exit 1
fi


tail -F /var/log/dovecot.log | while read -r line; do
    if echo "$line" | grep -q "Login: user=<[^@]\+@[^>]\+>"; then
        domain=$(echo "$line" | sed -n 's/.*Login: user=<[^@]\+@\([^>]\+\)>.*/\1/p')
        
        if [ -n "$domain" ]; then
            owner=$( /scripts/whoowns "$domain" )
            
            if [ -z "$owner" ]; then
                echo "Domain $domain does not exist."
            else
                echo "Domain $domain exists and is owned by $owner."
            fi
        fi
    fi
done