Extract all users with their last seen date?

Hi !

Is it possible to extract all users with their last seen date from MariaDB ?

Thanks.

What about using the occ command for this task:

#!/bin/sh

sudo -u www-data /srv/www/nextcloud/nextcloud/occ user:list --no-ansi --no-interaction | \
while read line
do
    user=`echo "${line}" | sed 's/^ *- *\([a-z0-9-]*\):.*$/\1/'`

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

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

Thanks j-ed !
Due to sed commands errors I made some changes :

#!/bin/bash
sudo -u www-data php /srv/www/html/domain.tld/occ user:list --no-ansi --no-interaction | \
while read line
do
    user=`awk -F: '{print $1}' <<< "${line}" | awk -F"- " '{print $2}'`

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

	echo "${user}:${last_seen}";
done
1 Like

Hi!

My users are synced to Nextcloud via LDAP.

I modified the script in a way that it only prints the correct names and last login date of the users who were already logged in.

However, some of the users are not displayed at all, although I can find them with user:list and read them out with user:info.
I see no difference to the found users.

Maybe someone else has an idea?

#!/bin/bash

sudo -u www-data php /var/www/nextcloud/occ user:list --no-ansi --no-interaction | \

while read line

do
    user=`awk -F: '{print $1}' <<< "${line}" | awk -F"- " '{print $2}'`

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

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

               if [ $last_seen != "1970-01-01T00:00:00+00:00" ]
                        then echo "${last_seen} : ${display_name}";

                        fi
done