Script "nc-who" - similar to unix `who`, follow live who is logged in

  • Have you ever wanted to check who’s online right now, if there’s any suspicious movement happening on your cloud?

  • Similar to unix who, follow live who is logged in with

nc-who

I have completely reworked this script, which was originally created here

It has a completely revised output. Since it updates at an adjustable refresh rate with watch, the formatted output from mysql was no longer usable. The solution was to output as html and back with html2text and sed in a usable, nice and neat format.

This tool is primarily intended for administrators of Nextcloud instances with many users. Of course, this is not intended for small servers used in familiary circles. But they can also want to take a look and then the tool is not far:

Restriction: only for MySQL/MariaDB Supported databases: MySQL/MariaDB, PostgreSQL

Read code here: https://global-social.net/script/nc-who

Install this way:

sudo wget -qO /usr/local/bin/nc-who https://global-social.net/script/nc-who
sudo chmod +x /usr/local/bin/nc-who
nc-who

Now simply run

nc-who monitor

or

nc-who last

much luck with it. :+1:


New in version:

  • 2023.06.28 05:13

    • PostgreSQL support
  • 2023.06.29 20:00

    • Auto-update with auto-backup: The script can now safely update itself. Backups are created that can be restored.
  • 2023.07.02 01:15

    • PostgreSQL output is now same as MySQL/MariaDB output.
    • Improvements and bug fixes.
  • 2023.08.11 16:00

    • Added realtime login status (online, offline or away) of user in monitor view
    • Added function ‘last_login’:
      • List users sorted by their last login time. This is equivalent to the output of
        occ user:lastseen --all
        Note: ‘--all’ is actually not available for ‘occ user:lastseen
  • 2023.08.12 23:25

    • Improved ‘last_login’ to also include users that never loged in.
4 Likes
  • Only mysql as database, pgsql is not yet supported by this script

What a pity …

@abyss02 try the newest version, I integrated PostgreSQL support for you.

1 Like

Well done!

I kinda like to move this thread to “howto”-category. What do you think about it, @ernolf ?

Aww and is there any chance. making this an app for appstore with kind of like a html (or whatever)-output for admins?

anyway… great work!

1 Like
  • :white_check_mark: done

Wooo, works great …

1 Like

Thank you for your kind feedback! I am happy that postgre - thanks to you - works now :wink:

I’ve increased the functionality of nc-who a bit again. Specialy the last_login function could be interesting for some admins but the realtime login status in monitor view as well.

Here the new help screen:

Help:

  nc-who - Version 2024-02-28 14:02 (latest version)

  This utility is similar to the Unix `who` command, allowing you to monitor
  live user logins and activities on your nextcloud server-instance.

  Usage:
    nc-who -h|--help
    nc-who monitor
    nc-who last
    nc-who integrity_check

  Options:

    -h|--help       Display this help message.

    monitor     Monitor live user logins, ordered by last activity at an
                adjustable refresh rate.
                * Login status is only available for cookie-based sessions
                  on a web frontend.
                * Last activity is shown for all clients.

    last        List users sorted by their last login time. This is equivalent
                to the output of `occ user:lastseen --all`
                * `--all` is actually not available for that occ command.

    integrity_check
                verify the integrity of this script with signature

Those of you who already have it installed (version 2023.06.29 or newer) only need to call the script and the update will be offered automatically.

Feedback welcome!

Continued luck

ernolf

Found a small bug in the current nc-who script.
If using nc dbpass with “$” sign, line 400 fails because “$” is used unescaped.

It must read:

eval '$DB_STRG' $DB_EXEC\"$db_query\"$

Thank you very much for your feedback!

Your Issue is verry good, I did realy not test it with passwords containing ‘$’

Could you please restart the script, it will ask to update and try if it now works.

ernolf

That was fast. It works now. Thanks.

1 Like

Unfortunately this breaks support for postgresql. I will have to develop a better solution. :wink:

Much luck,
ernolf

Now I hope it supports all kind of passwords for both, MySQL/MariaDB and PostgrSQL.

@atomic : does it still work?

ernolf