Keeping Bash Session Alive 

Newsgroups:  comp.os.linux.misc
Date:        Fri, 11 Jun 2004 13:25:04 GMT

A bash session through a firewall to linux gets timed out after a certain amount of minutes of inactivity. Is there something I can do in the shell to make it seem like it is alive? It seems that anything I do would be a background process and spawn another shell.

Keeping Bash Session Alive 

What I do is to setup a script that send an 'ls' along the pipe and then sleep for 5 minutes, then send another ls and so on… ok, it's crude and it's uggly but… hey! it works!

Davide

Keeping Bash Session Alive 

> [quoted text muted]

More like

#!/bin/bash
# in file ~/bin/keepalive.sh
while true ; do
   echo " " ; sleep 300
   done
# end script

just execute "keepalive.sh &" from your session and "kill %1" before logging out. The spaces it echoes may screw up formatting but they'll be easier to remove than the output from ls.

Matt G

Keeping Bash Session Alive 

how about:

(while true ; do echo -ne "\000" ; sleep 300 ; done ) &

As far as i can work out, the null chars do get sent to the controlling tty, but aren't displayed, so they won't screw up the display (except if they get inside escape sequences).

http://www.niftybits.ukfsn.org/

Keeping Bash Session Alive 

> [quoted text muted]

Assuming you are using ssh, you should, simply use 'ClientAliveInterval' and 'ClientAliveCountMax'.

Try 'man sshd_config' for more info, that usually prevents firewalls from closing connections.

Michael Heiming

Keeping Bash Session Alive 

> [quoted text muted]

An alternative you might actually prefer is GNU Screen. This makes your session a "virtual" session that survives a disconnection. If the bash session is killed—via time out or logging out or whatever—then the screen session survives. You can log into another bash shell and reconnect with the orphaned screen session. You can even spawn multiple screen sessions and flip from one to another, or even view multiple sessions in text "windows" on the same terminal. You can even remotely disconnect a screen session from one term and then connect it to your current term (i.e. you've walked to another computer and want to move your screen session to this computer).

With screen, you won't have to worry about your bash session timing out—you can just start up a new bash shell and continue with your disconnected session! From a security standpoint, you and your sysadmin may actually prefer this solution.

http://www.gnu.org/software/screen/

Isaac Kuo