LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   SSH disconnect, connect to process (https://www.linuxquestions.org/questions/linux-general-1/ssh-disconnect-connect-to-process-495100/)

briel 10-24-2006 08:18 AM

SSH disconnect, connect to process
 
I've been thinking about how to recover from a remote SSH disconnect, when the process is still present until the system automatically kills it. For example, if I am in my editor in SSH remotely, and I am disconnected for one of various reasons, and then I reconnect to the same host and see that there is a process present with my editor up and running in it (for a period of time). Since I am logged in again as the same user, could there be a way to reconnect to that "hanging" process before it is auto-killed, and gracefully save my changes?
CB

meetscott 11-24-2006 03:19 PM

The server ususally drops the connection when there is no activity. One way I keep connections going, is when I'm tailing a log file. This works for active log files. If there is nothing coming into the logs then it will drop eventually.

I wonder if you couldn't run a batch job in the back ground with a "sleep" function in there just to generate some activity so you remain connected. Make it like "sleep 300", for 5 minutes. Then keep executing some function that's benign like "uptime" that would output to the console once in a while. Hmmm. You got me thinking about how to keep the connection going :D

Don't know a way to reconnect though. I will watch this thread and see if someone else has an idea.

matthewg42 11-24-2006 04:32 PM

Consider running your editor in screen (if it's installed on the remote machine). You can re-connect to screen after you log back in.

Failing that, you might try to trap signals which are sent to your shell by the server. I would imagine it will send SIGHUP or SIGTERM to the login shell when it wants to auto-disconnect you. If it sends SIGKILL, there's nothing you can do, but maybe not. You could try this, but bare in mind you may well get the sysadmin chasing you with a scimitar for doing this...

Alter your .bash_profile (or if you are using a different shell, whatever file is executed on login):
Code:

function nokillme () {
    echo "ignoring signal - hahaha" > /dev/null
}

trap nokillme HUP INT TERM QUIT



All times are GMT -5. The time now is 06:45 AM.