Snippets

RuWeb.net Replace non-existent user emails with reseller email

Created by Andrey Chesnakov last modified
#!/bin/sh
for email in $(grep "F=<admin@$(hostname).*route error" /var/log/exim/mainlog | awk '{print $12}' | sort -u); do 
    domain=${email#*@}
    user=$(grep "$domain" /etc/virtual/domainowners | awk '{print $2}')
    [ -z "$user" ] && user=$(grep ^username= $(grep -l "email=$email" /usr/local/directadmin/data/users/*/user.conf || echo "/dev/null" | head -n1 ) | awk -F= '{print $2}')
    [ -z "$user" ] && echo "User not found from $email!" && continue
    creator=$(grep ^creator= "/usr/local/directadmin/data/users/$user/user.conf" | awk -F= '{print $2}')
    cemail=$(grep ^email= "/usr/local/directadmin/data/users/$creator/user.conf" | awk -F= '{print $2}')
    echo "$email->$cemail"
    replace "email=$email" "email=$cemail" -- "/usr/local/directadmin/data/users/$user/user.conf"
done

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.