Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux scp background runs transfer files

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Linux scp sets up nohup background operation

1. Execute the scp command normally

two。 Enter ctrl + z to pause the task

3.bg put it in the background.

4.disown-h ignores the HUP signal for this job

5. The test session is interrupted and the continued operation of the task is not affected.

1. Execute the scp command normally

Copy a folder from the oradb30 machine to the oradb31 machine:

Scp-r / u01/media/Disk1/ 192.168.1.31:/u01/media/

[root@oradb30] # scp-r / u01/media/Disk1/ 192.168.1.31:/u01/media/reverse mapping checking getaddrinfo for bogon failed-POSSIBLE BREAK-IN ATTEMPT rootstocks 192.168.1.31's password:. Filegroup2.jar 100% 84KB 83.8KB/s 00:00 filegroup9.jar 100% 16KB 16.1KB/s 0012. Enter ctrl + z to pause the task

Enter ctrl + z to pause

[1] + Stopped scp-r / u01/media/Disk1/ 192.168.1.31:/u01/media/ [root@oradb30 ~] #

Check the jobs at this time:

[root@oradb30 ~] # jobs [1] + Stopped scp-r / u01/media/Disk1/ 192.168.1.31:/u01/media/ [root@oradb30 ~] # 3.bg put it in the background

Bg puts the task number in the background:

[root@oradb30 media] # bg 1 [1] + scp-r Disk1/ 192.168.1.31:/u01/media/ &

Check that the task is already running in the background:

[root@oradb30 media] # jobs [1] + Running scp-r Disk1/ 192.168.1.31:/u01/media/ & 4.disown-h ignores the HUP signal for this job

Use disown-h to ignore the HUP signal for this job:

[root@oradb30 media] # disown-h% 1 [root@oradb30 media] # jobs [1] + Running scp-r Disk1/ 192.168.1.31:/u01/media/ &

Check the task running status and parent process number:

[root@oradb30 media] # ps-ef | grep scproot 12704 12638 0 05:19 pts/0 00:00:01 scp-r Disk1 192.168.1.31 / u01/media/root 12705 12704 8 05:19 pts/0 00:00:17 / usr/bin/ssh-x-oForwardAgent no-oPermitLocalCommand no-oClearAllForwardings yes 192.168.1.31 scp-r-t / u01/media/root 12823 12638 0 05:22 pts/0 00:00:00 grep scp5. The test session is interrupted and the continued operation of the task is not affected.

Disconnect the session to test whether the task can continue to run in the background:

[root@oradb30 media] # exitlogoutLast login: Thu Jan 5 05:19:50 2017 from 192.168.1.198 [root@oradb30] # [root@oradb30] # ps-ef | grep scproot 12704 10 05:19? 00:00:02 scp-r Disk1 192.168.1.31 / u01/media/root 12705 12704 8 05:19? 00:00:17 / usr/ Bin/ssh-x-oForwardAgent no-oPermitLocalCommand no-oClearAllForwardings yes 192.168.1.31 scp-r-t / u01/media/root 12854 12829 0 05:22 pts/2 00:00:00 grep scp

It was found that the scp task continued to run without being interrupted because the session was disconnected, and the parent process number changed to 1.

You can also refer to this method if you have other tasks that need to be run in the nohup background, but you forget to use nohup when you execute them.

If you configure ssh to log in without a password, you can also directly nohup scp.. & execute.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report