Accounts That Are Not Active in Zimbra: 5 Proven Filters

Finding accounts that are not active in Zimbra comes down to one attribute, zimbraLastLogonTimestamp, and one LDAP search. The old version of this post gave a filter and a 90-day script that look right but miss users who never logged in, build the date in the wrong time zone, and include a one-liner that can never match because of a single capital letter. This rewrite tests every filter against a real directory, so you can list accounts that are not active and trust the result before you lock or delete anything.

Lab note: Zimbra itself is not installed here. The tests run on OpenLDAP slapd in a debian:13 container, with zimbraLastLogonTimestamp defined the way Zimbra's source (AttributeManagerUtil.java) defines every gentime attribute: generalizedTimeMatch for equality and generalizedTimeOrderingMatch for ordering. ldapsearch stands in for zmprov sa, which takes the same LDAP query. Five test users cover the cases: one recent login, one old login, one that never logged in, one closed and one locked. "Today" in the lab is 2026-11-06.

Where Zimbra stores the last login time

The Zimbra attribute file (zimbra-attrs.xml) describes zimbraLastLogonTimestamp as a "rough estimate of when the user last logged in". It is rough on purpose: a second attribute, zimbraLastLogonTimestampFrequency, sets how often the value is written, with a default of 7d, and a value of 0 turns the updates off completely. So a user who logged in yesterday can still show a date several days old. That is fine for a 90-day check, where accounts that are not active for months stand out clearly, but do not use it as an audit log.

The value is an LDAP generalized time in UTC, for example 20260310121500Z. To read it as a date:

$ v=20260310121500Z; date -u -d "${v:0:8} ${v:8:2}:${v:10:2}:${v:12:2}" +%F\ %T\ UTC
2026-03-10 12:15:00 UTC

One more thing from the Zimbra Administrator's Guide: the last logon time is "ephemeral data". By default it stays in LDAP (zimbraEphemeralBackendURL = ldap://default), but large systems can move it to SSDB. The guide also says the value is returned by zmprov ga "only if the -l flag is not used". If your server uses SSDB, an LDAP search on this attribute will not see the real values, so check that setting first with zmprov gcf zimbraEphemeralBackendURL.

List accounts that are not active since a date

The admin guide gives the syntax searchAccounts (sa) [-v] {ldap-query} [limit] [offset] [sortBy {attribute}] [sortAscending 0 | 1] [domain {domain}]. The filter from the old post asks for a last login at or before a threshold. Here are the five lab users first, then the filter for accounts that are not active with a threshold of 8 August 2026:

mail: active@example.com
zimbraAccountStatus: active
zimbraLastLogonTimestamp: 20261101083000Z
mail: closed@example.com
zimbraAccountStatus: closed
zimbraLastLogonTimestamp: 20251201090000Z
mail: locked@example.com
zimbraAccountStatus: locked
zimbraLastLogonTimestamp: 20260801070000Z
mail: olduser@example.com
zimbraAccountStatus: active
zimbraLastLogonTimestamp: 20260310121500Z
mail: neverlogged@example.com
zimbraAccountStatus: active

$ zmprov sa equivalent: ldapsearch "(&(zimbraLastLogonTimestamp<=20260808000000Z))" mail
mail: closed@example.com
mail: locked@example.com
mail: olduser@example.com

The ordering match works on the generalized time, so the three old logins come back. But neverlogged@example.com is missing. An account that has never logged in has no zimbraLastLogonTimestamp at all, and an LDAP comparison on a missing attribute is never true. Those users are often the most important accounts that are not active: mailboxes created for people who left before their first day, test users, forgotten service accounts.

Add the accounts that never logged in

The old post had the right second filter, (!(zimbraLastLogonTimestamp=*)), but used it on its own. Combine both with an OR so one search returns every account that is not active:

$ zmprov sa equivalent: ldapsearch "(!(zimbraLastLogonTimestamp=*))" mail
mail: neverlogged@example.com

$ zmprov sa equivalent: ldapsearch "(|(zimbraLastLogonTimestamp<=20260808000000Z)(!(zimbraLastLogonTimestamp=*)))" mail
mail: closed@example.com
mail: locked@example.com
mail: olduser@example.com
mail: neverlogged@example.com

A new account also has no timestamp until its first login, so it looks like the other accounts that are not active: a user created this morning will show up too. Before you act on the list, check each account's creation date (zimbraCreateTimestamp in zmprov ga) or the "created" column of zmaccts.

Skip accounts that are already closed or locked

The list above still contains closed and locked accounts, which are already handled. Wrap the search in an AND with zimbraAccountStatus=active to see only the accounts that are not active in practice but still open:

$ zmprov sa equivalent: ldapsearch "(&(zimbraAccountStatus=active)(|(zimbraLastLogonTimestamp<=20260808000000Z)(!(zimbraLastLogonTimestamp=*))))" mail
mail: olduser@example.com
mail: neverlogged@example.com
LDAP search that lists accounts that are not active, including users who never logged in
The combined filter in the OpenLDAP lab: an old login and a user who never logged in, both still active.

On a Zimbra server the same query goes to zmprov sa as the zimbra user:

su - zimbra
zmprov sa "(&(zimbraAccountStatus=active)(|(zimbraLastLogonTimestamp<=20260808000000Z)(!(zimbraLastLogonTimestamp=*))))"

Filter mistakes that return nothing

LDAP filters fail in two different ways, and only one of them shows an error. Both came up when testing variations of the query for accounts that are not active.

There is no > or < operator in LDAP, only >= and <=. A strict comparison is a syntax error:

$ ldapsearch "(zimbraLastLogonTimestamp>20260808000000Z)"
ldap_search_ext: Bad search filter (-7)

A date without the time and the Z is worse, because nothing tells you it is wrong. 20260808 is not a valid generalized time, so the comparison is undefined for every entry, and the search returns no entries with exit status 0:

$ ldapsearch "(zimbraLastLogonTimestamp<=20260808)"
[exit 0]

An empty result for a query about accounts that are not active is suspicious on any server with more than a handful of users. Test the filter once with a threshold far in the future (every account with a timestamp must come back) before you trust an empty list.

Build the 90-day threshold correctly

The old script built the date with date -d '90 days ago' +%Y%m%d000000Z. That uses the local date and then writes Z (UTC) after it. On a server in UTC+7, run at 09:00 on 6 November:

$ TZ=Asia/Ho_Chi_Minh date
Fri Nov  6 09:00:00 +07 2026
$ date -d "90 days ago" +%Y%m%d000000Z
20260808000000Z
$ date -u -d "90 days ago" +%Y%m%d%H%M%SZ
20260808020000Z

Here the difference is only a few hours, and with a weekly timestamp it rarely changes the result. Still, date -u gives a value that means what it says. The corrected script, which also takes the number of days as an argument and includes the users who never logged in:

#!/bin/bash
# inactive_accounts.sh [days]  - run as the zimbra user
days=${1:-90}
t=$(date -u -d "$days days ago" +%Y%m%d%H%M%SZ)
echo "Active accounts with no login since $t (or never):"
zmprov sa "(&(zimbraAccountStatus=active)(|(zimbraLastLogonTimestamp<=$t)(!(zimbraLastLogonTimestamp=*))))"

The date line and the filter are the ones tested above; the zmprov sa call itself needs a real Zimbra server, so run it there first with a small number of days and compare with a few accounts you know.

Check one account and the zmaccts report

The old one-liner for a single account was zmprov ga account | grep zimbraLastLogonTimeStamp. The attribute name ends in Timestamp with a lower-case "s", and grep is case sensitive, so the command prints nothing even when a value exists. Tested on the entry of olduser:

$ grep zimbraLastLogonTimeStamp ga-output.txt
[exit 1]
$ grep -i zimbraLastLogonTimestamp ga-output.txt
zimbraLastLogonTimestamp: 20260310121500Z
[exit 0]

On Zimbra, use zmprov ga user@example.com | grep -i zimbraLastLogonTimestamp, or copy the attribute name exactly. Do not add -l here if your ephemeral data is in SSDB, as explained above.

For a whole-server overview, the admin guide says zmaccts "lists all the accounts, their status, when they were created and the last time anyone logged on", followed by a domain summary. The script copied in the old post started with zmaccts | grep closed, so it reported only closed accounts, not accounts that are not active. If you want that per-account report with quota and mailbox host, feed it the output of the zmprov sa search instead of grep closed. To read the account status values themselves, see how to check Zimbra account status.

What to do with accounts that are not active

Deleting accounts that are not active is the last step, not the first. zmprov da removes the account and its mailbox, and the old post's promise that zmrestore brings it back only holds if you run the backup tools of Zimbra Network Edition and have a backup from before the deletion. A safer order:

  1. Export the list of accounts that are not active: zmprov sa "<filter>" > inactive_accounts.txt, and keep it with the date.
  2. Ask managers to confirm each mailbox, especially the ones that never logged in.
  3. Lock the confirmed accounts first: zmprov ma user@example.com zimbraAccountStatus locked. A locked user who still needs the mailbox will call you, and unlocking is one command.
  4. After a waiting period, close or delete, and only after a backup of the mailbox.

The notification loop from the old post (mail -s ... $email for each line) sends mail to users who, by definition, do not read it. Send the warning to their manager or use it only for accounts with an old login, not for accounts that never logged in.

Summary

To find accounts that are not active in Zimbra, search on zimbraLastLogonTimestamp <= a full UTC generalized time, OR the accounts with no timestamp at all, AND zimbraAccountStatus=active. Remember that the timestamp is only updated every 7 days by default, that a short date or a > gives you an empty or failed search, and that SSDB setups need zmprov ga without -l. The full attribute and command reference is in the Zimbra Administrator's Guide.

Comments

Popular posts from this blog

How to Play Minecraft Bedrock Edition on Linux: A Comprehensive Guide for Tech Professionals

Linux desktop frozen? My 5 go-to tricks to try - before forcing a hard reboot

The Ultimate Guide: How to Set Up DXVK in Wine on Linux for Enhanced Gaming Performance