Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to run my application in screen when specific users are logged out and kill the screen when someone from my user list logged in. So I am thinking about bash script, which will be called periodically from cron and:

  1. Checks if specific users are logged in.
  2. If nobody is logged in - spawn screen and save pid to file or do nothing if pid file already exists
  3. If someone is logged in - read pid from file and kill screen

I am looking for more sophisticated alternatives, which will eliminate periodically running script from cron.

share|improve this question
up vote 3 down vote accepted

Several obvious options:

  1. modify /etc/profile to add a logout hook (or if your system already has a logout hook file, modify that)
  2. modify the system PAM configuration to add an extra session controller (pam_script library specifically addresses this)
  3. modify the login shell of the users under consideration to something which kills your other program on startup, spawns the real login shell, and then launches the screen program when the real login shell exits
  4. (if you only care about console logins) replace getty
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.