Accounts created Report

Revision as of 07:30, 19 August 2009 by Deon (talk | contribs) (New page: 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 # consulti...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

  1. !/bin/bash
  1. Zimbra reporting script for Accounts_created_in_Days
  2. Fred Strauss and Deon Lottering
  3. consulting@obsidian.co.za

VERSION=3.2

  1. How far back to search for, in ldapsearch time format

displaydate=`date -d "30 days ago" +%Y%m%d`"000000Z"

  1. Get ldap password from zimbra config

ldappass=`/opt/zimbra/bin/zmlocalconfig -s -m nokey zimbra_ldap_password`

  1. Get ldap dn from zimbra config

ldapdn=`/opt/zimbra/bin/zmlocalconfig -s -m nokey zimbra_ldap_userdn`

  1. Get ldap URL from zimbra config

ldapurl=`/opt/zimbra/bin/zmlocalconfig -s -m nokey ldap_url`

  1. ldapsearch and arguments

ldapsearch='/opt/zimbra/bin/ldapsearch' ldapargs="-LLL -x -H $ldapurl -w $ldappass -D $ldapdn "

  1. We're only interested in the e-mail address and creation time

ldapattrs="zimbraMailDeliveryAddress createTimestamp"

  1. 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 '

  1. Set Field Seperator to : and initialise our variables

BEGIN {FS=": ";email=0;timestamp=0}

  1. If line contains the email address, store it

/zimbraMailDeliveryAddress/ {email=$2}

  1. 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)}

  1. If the line contains dn: we know we are starting with a new entry, print our
  2. previous data and reset variables

/dn:/ {if (email) print email "," timestamp; email=0; timestamp=0}

  1. 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

Jump to: navigation, search