Linux 在后台运行 SCP 并监控进度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13147861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 17:39:33  来源:igfitidea点击:

Run SCP in background and monitor the progress

linuxscpnohup

提问by Tamas

I'm running an scpcommand in the background:

scp在后台运行一个命令:

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

I entered the password - I hit ctrl-zto 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)?

我输入了密码 - 我点击ctrl-z停止命令并用 重新启动它bg,我可以通过执行jobs. 但是,有没有办法监控文件传输的进度(即,如果我在不将其置于后台的情况下运行它)?

Thank you.

谢谢你。

回答by user1786911

Maybe you can redirect STDERRto file and use tail -fto monitor it

也许您可以重定向STDERR到文件并用于tail -f监视它

回答by user1277476

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

你可以使用 screen(1) 或类似的,而不是 bg。

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

然后你可以 control-ad 分离和 screen -d -r 重新附加。

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.

您还可以根据需要注销并重新登录,而不会失去重新连接的能力,因此在不可靠的网络上非常有用。它可以追溯到人们通过串行调制解调器进行 Slip 和 PPP 时。

回答by user1277476

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

你可以使用 screen(1) 或类似的,而不是 bg。

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

然后你可以 control-ad 分离和 screen -d -r 重新附加。

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.

您还可以根据需要注销并重新登录,而不会失去重新连接的能力,因此在不可靠的网络上非常有用。它可以追溯到人们通过调制解调器进行 Slip 和 PPP 时,以及之前。

回答by user3284525

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

在运行 CentOS / Red Hat / Fedora 时,我只使用:

ps aux | grep scp

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

检查正在运行的 scp 进程。要查看他们是否在做任何事情,我喜欢使用:

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.

如果您打开AWS EC2,您可以切换到实例部分以监视启动卷上的网络和 r/w 操作。要查看其他驱动器正在执行的操作,请切换到 Volumes 部分中的 Monitoring 选项卡并选择一个卷。

回答by Fingashpitzzz

You can use watch tail nohup.outfor that

您可以使用watch tail nohup.out

回答by Hassan Raza

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

您可以使用tail命令查看 nohup.out 的输出。只需在终端上写下以下命令即可。

tail -n 10 -f nohup.out

尾 -n 10 -f nohup.out

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

-n 10 告诉要显示的内容末尾的行数。

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

-f 告诉命令遵循 nohup.out。显示执行命令后将写入文件的每个内容。

回答by Tarang Bhalodia

You can use jobscommand to check the processes.

您可以使用jobs命令来检查进程。

For example jobs -lwill list all running processes along with the process id. Refer this sitefor reference.

例如jobs -l将列出所有正在运行的进程以及进程 ID。请参阅此站点以供参考。

回答by Aashutosh

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.

bg -> 将作业发送到后台。

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

disown -h %1 -> 即使您退出系统,它也会让它运行

回答by ucsky

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

对我来说只使用详细模式会附加一些东西 nohup.out

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

After you can monitor using tail -f nohup.out

在您可以使用监控之后 tail -f nohup.out