Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com
huuphan.com. Powered by Blogger.

list accounts that has not logged in for the last x days in zimbra

How to list accounts that has not logged in for the last x days in zimbra, list accounts last login time a month ago...
 list accounts that has not logged in for the last x days in zimbra





after run script,The output /tmp/lastlogin_time syntax file as bellow
Account zimbraAccountStatus displayName
To use date command a month ago
date -d "-1 month" +%Y%m%d
The script zimbra_lastlogin.sh name, list accounts last login time a month ago
To run script zimbra_lastlogin.s
./zimbra_lastlogin.sh
The full script zimbra_lastlogin.sh list accounts that has not logged in for the last x days in zimbra
#!/bin/bash
#HuuPV author
rm -f /tmp/lastlogin_time
pastmonth=$(date -d "-1 month" +%Y%m%d)
LDAP_HOST=$(/opt/zimbra/bin/zmlocalconfig ldap_host | cut -d\ '' -f3)
LDAP_PASSWORD=`/opt/zimbra/bin/zmlocalconfig -s zimbra_ldap_password | cut -d\ '' -f3`
LDAP_USERDN=$(/opt/zimbra/bin/zmlocalconfig zimbra_ldap_userdn | cut -d\ '' -f3)
LDAPSEARCH="/opt/zimbra/bin/ldapsearch -D "$LDAP_USERDN" -w$LDAP_PASSWORD -H ldap://$LDAP_HOST -LLL -o ldif-wrap=no"
ZIMBRA_ACCOUNT_STATUS="zimbraAccountStatus"
$LDAPSEARCH "(&(zimbraLastLogonTimestamp<="$pastmonth"000000Z)(!(zimbraIsSystemResource=TRUE))($ZIMBRA_ACCOUNT_STATUS=active)(mail=*)(&(objectclass=zimbraAccount)(!(objectclass=zimbraCalendarResource))))"  $ZIMBRA_ACCOUNT_STATUS displayName | sed 's/ou=people,//g' | sed 's/dn: uid=/:/g' | sed 's/,dc=/@/' | sed 's/,dc=/./g' | sed 's/,dc=/./g' | sed ':a;N;$!ba;s/\n/ /g' | sed "s/$ZIMBRA_ACCOUNT_STATUS: //g" | sed "s/displayName: //g" | sed 's/:/\n/g' | sed '/^\s*$/d' | sort >> /tmp/lastlogin_time

post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com