# [ssh] stop service after logout?

## avx

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.

----------

## mokia

Something like this?

```
#!/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

```

----------

## avx

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.

----------

