Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[ssh] stop service after logout?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Sat Nov 19, 2011 3:18 pm    Post subject: [ssh] stop service after logout? Reply with quote

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
View user's profile Send private message
mokia
n00b
n00b


Joined: 01 Feb 2010
Posts: 63
Location: Hungary

PostPosted: Sat Nov 19, 2011 5:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Sat Nov 19, 2011 9:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum