[Nottingham] Putting remote ssh processes into the background

Dylan Swift dylan.swift at gmail.com
Fri Mar 12 09:12:18 UTC 2010


On 12 March 2010 03:49, Going It Alone <reggaemaker at googlemail.com> wrote:
> This may be the solution:
> http://www.rackaid.com/resources/linux-screen-tutorial-and-how-to/
>
> Quote: "The second way to leave screen is to detach from a windows.
> This method leaves the process running and simple closes the window.
> If you have really long processes, you need to close your SSH program,
> you can detach from the window using “Ctrl-A” “d”. This will drop you
> into your shell. All screen windows are still there and you can
> re-attach to them later."

Screen is ideal if you need to be able to re-attach later to an
interactive process (eg to check on progress, answer user queries),
and I use it a lot when managing systems where I am not confident in
the connection, or the penalty for the task terminating incorrectly is
high (for example system updates or customer system modifications)

crib sheet:

1.
# screen
this starts a new screen session

2.
when in a screen session, <ctrl>+a, followed by d (not <ctrl>+d) will
detach from a screen, leaving it running in the background

you will return to your original shell with a 'detached' message

3.
# screen -r <pid>
or
# screen -x      (if there is only 1 screen running in the background)
will re-attach to the former screen

4.
when in a screen session:
# exit
will terminate the shell, and if no more shells are present will
terminate screen.

5.
when in a screen session, <ctrl>+a, followed by c (not <ctrl>+c) will
create an additional shell

6.
when in a screen session, <ctrl>+a, followed by n, or p will jump from
the current shell to the next or previous shell if there is more than
one shell associated with a screen session.

7.
outside of screen:
# screen -d -m <command>
will start screen, get it to run <command> and not attach to it -
effectively backgrounding the task without the manual interaction.

^^^ this one is useful if you need to run the same command on multiple
machines, but do not want to wait for each one to complete before
moving on to the next host. - 'parallel-ising' (if there is such a
word) a task.





Also useful (and more traditional) is nohup:

nohup <command> &

will drop your command into the background, and detach it from the
shell. There will be no way to interact with this process (that I know
of), other than by sending signals using the kill command. This is
ideal if the command will self terminate (like a download).

Hope that helps, rather than confuses!


Dylan


> On 12 March 2010 00:47, Simon Sleaford <simon.sleaford at gmail.com> wrote:
>> Hello all
>> I'm running a small server at home, using it to download podcasts and
>> iplayer shows mainly. If I ssh into the machine I can start process off
>> nicely but I can't close the terminal on my local machine otherwise it ends
>> the remote process. I've tried using [command] & and also using ctrl-z and
>> bg but still the process will end if I want to close my terminal on my local
>> machine.
>> Any tips? I'm new to ssh (never needed it until I built this machine) so
>> still learning.
>> Thanks
>> Simon
>> _______________________________________________
>> Nottingham mailing list
>> Nottingham at mailman.lug.org.uk
>> https://mailman.lug.org.uk/mailman/listinfo/nottingham
>>
>
>
>
> --
> Click the link below and tune in to {Een-Gesin Net Radio}
>
> http://een-gesin.kicks-ass.org
>
> Or hear my stuff at:
>
> http://www.myspace.com/g01ng1tal0ne
>
> _______________________________________________
> Nottingham mailing list
> Nottingham at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/nottingham
>



More information about the Nottingham mailing list