A user was running a script on a linux server. His connection timed out. Is there a way to view the process information again just like before the connection timed out. The script is currently running.
For example:
user@server$ ./awesomeScript.sh
(connection dies)
How to get back to as if the script was running on that command line to see any out put?
I had no answer at hand either, but after googling it seems thats not a possible or at least no feesable way to do that;
Either wait for your script to die or kill it from another ssh session, and in the futur use screen or tmux so you can reconnect to the shell the scrip is running with another ssh session.
Top answer from serverfault:
Attempting to connect a new terminal's current STD* file descriptors to an old running process is just asking for trouble. Even if you do manage to do that, the terminal's job control won't work as expected. You'll have a mess left behind if you eventually exit the taken-over program, and what happens to the shell that sacrificed its file descriptors to be handed to the newly-backgrounded process. Will ssh stay open when that shell goes away? Probably not. So you'll need to redirect it somewhere else first.Possible or not, I'd wager that it's more desirable to just let the abandoned process get killed "naturally". If you're doing anything important enough to justify trying to do all the hackery required to resume control and you're on an unstable link, you should probably know that in advance and just use screen (or vnc, or whatever floats your detached-control boat). :)
you could pipe the output to tee (maybe stderr to another file too). additionally I would always suggest running programs in either tmux or screen. alternative you could use mosh https://mosh.mit.edu/ (but I've only heard & never used it)
If you get disconnected from a server while running a long running program that you need the output from, you should always be directing that output to either a file, or as suggested by @mauli, running tmux or screen.
Thanks for the replies. I looked into nohup and it looks like it directs the stdout and stderr into a file by default, and it will run the job even if a hang up signal is sent.
Not totally familiar with nohup, but seems like a good solution. Thoughts???
nohup works, but it doesn't let you reconnect to the running process. (screen works well if you want that) If you are already running a script, you can leave it running after disconnect by disowning it from the shell.
./awesomescript ctrl-z bg disown %1
or, even " disown ./awesomescript 2>&1 >> nohup.out "