Accounts created Report

From Zimbra :: Wiki

Jump to: navigation, search
   Article-alert.png  - This article is a community contribution and may include unsupported customizations for network edition customers.



Script was written do Report on accounts created in a certain time period.

#!/bin/bash
# Zimbra reporting script for Accounts_created_in_Days
# Fred Strauss and Deon Lottering
# How far back to search for, in ldapsearch time format
displaydate=`date -d "30 days ago" +%Y%m%d`"000000Z"
# Get ldap password from zimbra config
ldappass=`/opt/zimbra/bin/zmlocalconfig -s -m nokey zimbra_ldap_password`
# Get ldap dn from zimbra config
ldapdn=`/opt/zimbra/bin/zmlocalconfig -s -m nokey zimbra_ldap_userdn`
# Get ldap URL from zimbra config
ldapurl=`/opt/zimbra/bin/zmlocalconfig -s -m nokey ldap_url`
# ldapsearch and arguments
ldapsearch='/opt/zimbra/bin/ldapsearch'
ldapargs="-LLL -x -H $ldapurl -w $ldappass -D $ldapdn "
# We're only interested in the e-mail address and creation time
ldapattrs="zimbraMailDeliveryAddress createTimestamp"
# ldapsearch for all zimbra accounts that are active, created on or after $displaydate
$ldapsearch $ldapargs -b  "(&(objectclass=zimbraAccount)(!(objectclass=zimbraCalendarResource))(zimbraAccountStatus=Active)(createTimestamp>=$displaydate))" $ldapattrs \
| awk '
# Set Field Seperator to : and initialise our variables
BEGIN {FS=": ";email=0;timestamp=0}
# If line contains the email address, store it
/zimbraMailDeliveryAddress/ {email=$2}
# If line contains the create time, store it in a more readable format
/createTimestamp/ {timestamp=substr($2,0,4) "-" substr($2,5,2) "-" substr($2,7,2)}
# If the line contains dn: we know we are starting with a new entry, print our
# previous data and reset variables
/dn:/ {if (email) print email "," timestamp; email=0; timestamp=0}
# If we reach the end of input, print the last entry
END {if (email) print email "," timestamp}' > /var/log/zimbra-reports/accounts_created_last_30_days_from_`date +%F`.csv
mutt -s "Accounts created in last 30 Days from `date +%F`" -a /var/log/zimbra-reports/accounts_created_last_30_days_from_`date +%F`.csv admin@domain.com < /usr/local/bin/accounts-30days

The file /usr/local/bin/accounts-30days will insert text into the body of your email


Verified Against: unknown Date Created: 8/19/2009
Article ID: http://wiki.zimbra.com/index.php?title=Accounts_created_Report Date Modified: 12/8/2009
Personal tools