2

I'd like to perform selective shutdown of a server in my house after backing-up over SSH. My post-backup script waits for five minutes and then runs a very short 'safe shutdown' script located on the server. This script was using who -q to get the number of users logged on, however as I started executing this script non-interactively, i.e. using ssh user@server /home/common/bin/SafeShutdown.sh (well actually using PuTTY's plink right now but should make no difference), the user count being found was 0 if no interactive users were present. How can I either get who/w to work with non-interactive logins, or else use another method as an unpriveliged user to count how many people are logged on in any way, shape or form?

Thanks

  • an easy thing to do is make your non-interactive ssh's use a pseudo-tty, then they will be counted. ssh -t. – meuh Sep 19 '15 at 17:06
  • Thanks, that works for me, the switch is the same for putty (although a little annoying as normally putty seems to use lower-case switches for disabling and upper-case for enabling capabilities!) It's a good, simple workaround but I don't feel it really answers the question so I'll wait a bit and if no-one else has anything to add I'll put it as an answer and mark it as solved. Thanks again! – stellarpower Sep 19 '15 at 18:33
0

As meuh says, the use of a pseudo-terminal may be forced with the -t option, and then the login will show-up with who. However whilst this a home system, if it weren't it still would concern me a little that if someone logged in without using that switch I might be unaware of his presence on my system without looking further into sshd's reporting options!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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