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

Maybe this will help you:

nc-who monitor basically makes this database query that repeats itself at an adjustable time interval:

MySQL:

SELECT FROM_UNIXTIME(at.last_activity) AS last_activity,
                        CASE
                          WHEN at.type = '0' AND at.remember = '1' THEN (SELECT us.status FROM oc_user_status us WHERE us.user_id = at.uid)
                          ELSE 'n.a.'
                        END AS status, 
                        at.uid, at.name AS client
                      FROM oc_authtoken at WHERE at.type = '0' AND at.remember = '1'
                      ORDER BY at.last_activity DESC

PostgreSQL:

SELECT TO_TIMESTAMP(at.last_activity) AS last_activity,
                        CASE
                          WHEN at.type = '0' AND at.remember = '1' THEN (SELECT us.status FROM oc_user_status us WHERE us.user_id = at.uid)
                          ELSE 'n.a.'
                        END AS status, 
                        at.uid, at.name AS client
                      FROM oc_authtoken at WHERE at.type = '0' AND at.remember = '1'
                      ORDER BY at.last_activity DESC

All the rest of the code is to format it correctly on as many terminals as possible, including less wide TTYs, and to make it work out of the box on as many systems as possible.


Much and good luck,
ernolf

1 Like