View previous topic :: View next topic |
Author |
Message |
avx Advocate
Joined: 21 Jun 2004 Posts: 2152
|
Posted: Sat Nov 19, 2011 3:18 pm Post subject: [ssh] stop service after logout? |
|
|
I've currently got some debugging help via SSH and since I usually don't have ssh on by default, I've been wondering, if there is a (simple) way to stop the daemon once the last connection is dropped and no other (successful) connection is established in X minutes? I know that there's auto-logout after idle, but that's not what I'm thinking about here. _________________ ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. |
|
Back to top |
|
|
mokia n00b
Joined: 01 Feb 2010 Posts: 63 Location: Hungary
|
Posted: Sat Nov 19, 2011 5:11 pm Post subject: |
|
|
Something like this?
Code: | #!/bin/bash
#mokia
#GPL
timeout="10"
while true;
do
exit=`ps aux | grep sshd | grep -v grep | grep @`
if [ "$exit" == "" ] ;
then
echo "no activ session detected"
let timeout=$timeout-1
echo $timeout
else
echo "activ session detected"
echo $exit
timeout=10
fi
if [ $timeout == "0" ] ; then
echo "Timeout! stopping sshd"
/etc/init.d/sshd stop
break
fi
# relogin timeout is 10×n sec where n is sleep [n]
sleep 5
done
|
|
|
Back to top |
|
|
avx Advocate
Joined: 21 Jun 2004 Posts: 2152
|
Posted: Sat Nov 19, 2011 9:43 pm Post subject: |
|
|
That's basically it, yes, thanks. Just thought there might be some config/switch in openSSH which I've missed.
I'll try your approach, but still leaving the thread open, maybe others have another idea. _________________ ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. |
|
Back to top |
|
|
|