I have a ReadyNAS 102 with a couple of USB drives attached, and connecting to it from a Windows 8 machine over SSH. There were times I wanted to copy files between volumes on the NAS. Unfortunately I have also accidentally cut off copying process by accidentally closing off the SSH sessions.

Is it possible for me to fork a cp or mv process on SSH? As it currently stands when I close the SSH session, be it by accidentally closing the terminal window or closing my laptop screen and putting it to sleep, the copy process stops.

Can I do something like cp ~/blah /some/other/path & and have the process keep running to completion in the background even if the SSH session is terminated?

  • 1
    What do you mean by "fork a cp or mv process"? Usually shell already forks and executes those programs. What is your goal? Resuming copies? See rsync. – Lekensteyn Jun 8 '14 at 11:16
  • I have edited the question to hopefully clarify it a little better. – codedog Jun 8 '14 at 21:20
  • The comment about rsync was the best answer here. I did a basic rsync -r /path/to/source /path/to/destination &, exited out of my remote SSH session and left it for a good while. Connected again over SSH to check the destination and... voila! All the files were copied over! Thank you @Lekensteyn for the suggestion. If you want to put that into an answer I will vote for it. – codedog Jun 9 '14 at 8:34
  • 1
    If rsync gets interrupted, you will still be left with a temporary file. It just helps you by not having to copy existing files over. What you actually need for persistent sessions is GNU screen as poste by Jake. – Lekensteyn Jun 9 '14 at 9:47

You are looking for gnu screen

Screen is a full-screen window manager that multiplexes a physical terminal between several processes, typically interactive shells. Each virtual terminal provides the functions of the DEC VT100 terminal and, in addition, several control functions from the ANSI X3.64 (ISO 6429) and ISO 2022 standards (e.g., insert/delete line and support for multiple character sets). There is a scrollback history buffer for each virtual terminal and a copy-and-paste mechanism that allows the user to move text regions between windows. When screen is called, it creates a single window with a shell in it (or the specified command) and then gets out of your way so that you can use the program as you normally would. Then, at any time, you can create new (full-screen) windows with other programs in them (including more shells), kill the current window, view a list of the active windows, turn output logging on and off, copy text between windows, view the scrollback history, switch between windows, etc. All windows run their programs completely independent of each other. Programs continue to run when their window is currently not visible and even when the whole screen session is detached from the users terminal.

In a nutshell it allows you to create "virtual terminals" that remain active until you kill them yourself. Any process running in a screen session remains active. If your ssh session terminates you just start a new session and re-attach the screen.

This article provides a good tutorial

  • My mistake, I didn't mention I am connecting from a Windows 8 machine. Is your answer applicable to *nix clients only? – codedog Jun 9 '14 at 6:59
  • Yes it is a *nix package, but a fast search shows that the readynas os is a Debian fork so a simple apt-get install screen on the readynas terminal should do the trick. The machine you use to connect can be any os, what matters is that screen is installed on the remote machine. – Jake Jun 9 '14 at 18:59
  • You're absolutely right. I installed byobu instead but it's just a bit of a fancier gnu screen as far as I could tell. – codedog Jun 11 '14 at 8:37
  • I did not know byobu yet, going to try it out on my mediaserver @ home. – Jake Jun 11 '14 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.