Get Active User Login Count from Dovecot



  • Tested on CentOS 7.

    To get active IMAP logins...

    cat /var/log/maillog | grep imap-login:\ Login | sed -e 's/.*Login: user=<\(.*\)>, method=.*/\1/g' | sort | uniq | wc -l
    

    To get active POP3 logins...

    cat /var/log/maillog | grep pop3-login:\ Login | sed -e 's/.*Login: user=<\(.*\)>, method=.*/\1/g' | sort | uniq | wc -l
    

    Log location based on CentOS default. If using Ubuntu, you will need to adjust the log name slightly. Keep in mind that this count is only for the length of the maillog retention. Want longer, use more archived maillogs in the cat command (cat combines files, remember?)

    If you want all logins, you need to grep for both imap and pop3 at the same time, or else you will count duplicates.



  • @scottalanmiller said in Get Active User Login Count from Dovecot:

    cat /var/log/maillog | grep pop3-login:\ Login | sed -e 's/.Login: user=<(.)>, method=.*/\1/g' | sort | uniq | wc -l

    This tiny variation will get you all logins from all logs that you have stored.

    cat /var/log/maillog* | grep pop3-login:\ Login | sed -e 's/.*Login: user=<\(.*\)>, method=.*/\1/g' | sort | uniq | wc -l