How to put scp in background


To execute any linux command in background we use nohup. But the problem with scp command is that it prompts for the password (if password authentication is used). So to make scp execute as a background process do this:


1>
$ nohup scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1
if it prompts for password then enter password.
Then press ctrl + z which will temporarily suspend the command, 


SCP will give output:
[1]+  Stopped   scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1


2>
then enter the command:
$ bg
This will start executing the command in backgroud


SCP will give output:
[1]+ scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1




3>
To see what background process that is running you can type command:


$ jobs
SCP will give output:
[1]+  Running  scp file_to_copy user@server:/path/to/copy/the/file > nohup.out 2>&1




To bring the process back to foreground you can use 'fg' command.

at Thursday, April 05, 2012  

2 comments:

Anonymous said... June 25, 2013 at 5:27 PM  

Thank you, resolved my problem

Anonymous said... April 18, 2014 at 6:47 PM  

Hi There,

I am trying the same but when i exit my putty session or putty session gets closed due to timeout, it stops scping. Also i do not see any jobs once i re-login. But if i do "ps -ef|grep scp" i can see the scp process there but it is hung as it is not scping anything.

Any suggestion in this case please ?

Post a Comment

Powered by Blogger.