[SOLVED] Signal when there are n users logged in via SSH
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm looking for a simple way to signal when there are n or more users logged into a particular system via SSH. In particular I want to trigger actions when the threshold is passed in either direction. It is easy to trigger an action as root via PAM when someone logs in or out but that by itself is full of race conditions and so I am wondering about the logic required to prevent race conditions with a lot of concurrent users and as well as some people logged into the same account multipe times.
Should I just try to keep a single persistent file containing a counter that is incremented and decremented on login and logout? Or is there a better way. A shell script is preferable.
The following environment variables are available to PAM:
DBUS_SESSION_BUS_ADDRESS
LANG
PAM_RHOST
PAM_SERVICE
PAM_TTY
PAM_TYPE
PAM_USER
PWD
SSH_AUTH_INFO_0
XDG_RUNTIME_DIR
XDG_SESSION_CLASS
XDG_SESSION_ID
XDG_SESSION_TYPE
Last edited by Turbocapitalist; 11-11-2019 at 12:01 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.