Accounts created Report

Revision as of 07:39, 19 August 2009 by Deon (talk | contribs)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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

# 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
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 < /usr/local/bin/accounts-30days

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

Jump to: navigation, search