Article 4TZ27 Signal when there are n users logged in via SSH

Signal when there are n users logged in via SSH

by
Turbocapitalist
from LinuxQuestions.org on (#4TZ27)
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
latest?d=yIl2AUoC8zA latest?i=NtPzwt2Yoic:NSFGTenDNOM:F7zBnMy latest?i=NtPzwt2Yoic:NSFGTenDNOM:V_sGLiP latest?d=qj6IDK7rITs latest?i=NtPzwt2Yoic:NSFGTenDNOM:gIN9vFwNtPzwt2Yoic
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments