Run SCP in background and monitor the progress

I'm running an scp command in the background:

 nohup scp file.gz root@target-host:/root/ > nohup.out 2>&1 

I entered the password - I hit ctrl-z to halt the command and restarted it with bg, and I can confirm that it's running by executing jobs. However, is there a way of monitoring the progress of the file transfer (i.e. if I would be running it without placing it in the background)?

Thank you.

2

9 Answers

You could use screen(1) or similar, instead of bg.

Then you can control-ad to detach and screen -d -r to reattach.

You can also log out and back in as needed, without losing the ability to reattach, so it's great over unreliable networks. It dates back to when people were doing Slip and PPP over modems, and before.

While running CentOS / Red Hat / Fedora, I simply use:

ps aux | grep scp 

to check on the running scp processes. To see if they are doing anything, I like to use:

du -s -c -h * 

If you are on AWS EC2, you can switch to the section Instances to monitor network and r/w operations on the boot volume. To see what additional drives are doing, switch to the Monitoring tab in the Volumes section and select a volume.

nohup scp <file_name> user@<IP_Address>:<path> nohup: ignoring input and appending output to 'nohup.out' user@IP_address's password: Ctrl+z bg disown -h %1 

bg -> Send job to background.

disown -h %1 -> this will let it run even when you log out of system

You can use jobs command to check the processes.

For example jobs -l will list all running processes along with the process id. Refer this site for reference.

Maybe you can redirect STDERR to file and use tail -f to monitor it

You could use screen(1) or similar, instead of bg.

Then you can control-ad to detach and screen -d -r to reattach.

You can also log out and back in as needed, without losing the ability to reattach, so it's great over unreliable networks. It dates back to when people were doing Slip and PPP over serial modems.

You can use watch tail nohup.out for that

You can use tail command to see the output from nohup.out. Just write down the following command on terminal.

tail -n 10 -f nohup.out

-n 10 tells the number of lines at the end of contents to display.

-f tells the command to follow the nohup.out. Display every content which will be written to the file after executing command.

For me only using verbose mode will append something to nohup.out

nohup scp -v file.gz root@target-host:/root/ > nohup.out 2>&1 

After you can monitor using tail -f nohup.out

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like