Get last login date for all users & Active users


As we try to show occ command user:lastseen , we cloud find an user last login as below.


How can we use this command for all user? Please kindly advise. Thank you in advance.

I just needed it today and wrote this small script. Make change accordingly and use it



cd $nextcloud_dir
sudo -u apache php occ user:list > $input

while IFS= read -r line
  username=`echo "$line" | awk '{ gsub(":",""); print $2}'`
  last_login=`sudo -u apache php occ user:lastseen $username |  awk '{ print $4 "-" $5'}`
echo "$line - $last_login" 
done < "$input"

Thank you for your information. We have tried it with OCC Web function,

which we just enabled in App

Is there any way we can do that command for all user via this OCC Web or not?

Thank you for your kind always support.

Its a bash script I posted, it wont work in OCC web session. You need to run it from SSH terminal. OCC web can just run occ commands.

das funktioniert soweit gut.
Aber bei einer Anmeldung als Anton Meier gibt es Probleme.
Kannst Du bitte es nochmal überprüfen?
Schön wäre es wenn man es auch anschließend als cron job laufen lassen kann um es bei Zeiten per Mail zu schicken

Danke im voraus

that works fine so far.
But there are problems when registering as Anton Meier.
The user name is Anton Meier.
Not only Anton.
With one Name it works fine.
But with complete Name no.
Can you please check it again?
It would be nice if you can also run it as a cron job afterwards so that you can send it by e-mail when the time comes

Thanks in advance

Sorry i could not get the old script to work. Maybe there is only a small error in the script e.g. "" or {} missing. But i never used it. :wink:

But you can use a from me minimal modified script i found here. Ok also this script i never used before because i do not need the feature. :wink: But it works with spaces in the names. :wink:


sudo -u www-data php /var/www/html/nextcloud/occ user:list --no-ansi --no-interaction | \
while read line
    user=`awk -F: '{print $1}' <<< "${line}" | awk -F"- " '{print $2}'`

    last_seen=`sudo -u www-data php /var/www/html/nextcloud/occ user:info --no-ansi --no-interaction "${user}" | \
               grep "last_seen:" | sed 's/^.*last_seen: *//'`

	echo "${user}:${last_seen}";

It would be a nice feature to get this information with occ user:list directly.

Thank you.
It’s okay now.