How to put a command over SSH in background ? - Unix

This is a discussion on How to put a command over SSH in background ? - Unix ; Assume I opened a SSH session to a remote Linux server. I want to start a long running command on that remote system and put that command in background so that I can logout (from SSH session) while the command ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: How to put a command over SSH in background ?

  1. How to put a command over SSH in background ?

    Assume I opened a SSH session to a remote Linux server.

    I want to start a long running command on that remote system and put that command in background
    so that I can logout (from SSH session) while the command is still running and not aborted.

    Normally I would have to put the command in such a case in background by appending a " &" at the end
    of the command line. However this does not work if I redirect the output like in:

    rsync ...... >>logfile 2>&1 &

    I guess I have to mask the appended "&".

    How do I do this otherwise?

    Sabine

  2. Re: How to put a command over SSH in background ?

    At 06 May 2008 21:20:51 GMT gizmo_3@yahoo.de (Sabine Elsner) wrote:

    >
    > Assume I opened a SSH session to a remote Linux server.
    >
    > I want to start a long running command on that remote system and put that command in background
    > so that I can logout (from SSH session) while the command is still running and not aborted.
    >
    > Normally I would have to put the command in such a case in background by appending a " &" at the end
    > of the command line. However this does not work if I redirect the output like in:
    >
    > rsync ...... >>logfile 2>&1 &
    >
    > I guess I have to mask the appended "&".
    >
    > How do I do this otherwise?


    ssh remote.machine.whatever sh -c 'nohup rsync ...... >>logfile 2>&1 &'

    Note: 'logfile' lives on the remote machine's file system. You have to
    quote the whole command string and pass it to a 'super' shell, one that
    will exit once the background job fades into the background. nohup
    prevents the forked process from being killed when the parent (super)
    shell exits.

    >
    > Sabine
    >


    --
    Robert Heller -- Get the Deepwoods Software FireFox Toolbar!
    Deepwoods Software -- Linux Installation and Administration
    http://www.deepsoft.com/ -- Web Hosting, with CGI and Database
    heller@deepsoft.com -- Contract Programming: C/C++, Tcl/Tk


+ Reply to Thread