闲者博客 - scp
https://bk1314.com/tag/scp/
-
Linux scp 设置nohup后台运行
https://bk1314.com/23.html
2022-02-23T22:16:14+08:00
1.正常执行scp命令从oradb30机器拷贝一个文件夹到oradb31机器:[root@oradb30 ~]# scp -r /u01/media/Disk1/ 192.168.1.31:/u01/media/
reverse mapping checking getaddrinfo for bogon failed - POSSIBLE BREAK-IN ATTEMPT!
[email protected]'s password:
...
filegroup2.jar 100% 84KB 83.8KB/s 00:00
filegroup9.jar 2.输入ctrl + z 暂停任务[1]+ Stopped scp -r /u01/media/Disk1/ 192.168.1.31:/u01/media/
[root@oradb30 ~]# 此时查看jobs:[root@oradb30 ~]# jobs
[1]+ Stopped scp -r /u01/media/Disk1/ 192.168.1.31:/u01/media/
[root@oradb30 ~]# 3.bg将其放入后台[root@oradb30 media]# bg %1
[1]+ scp -r Disk1/ 192.168.1.31:/u01/media/ &4.disown -h 将这个作业忽略HUP信号[root@oradb30 media]# disown -h %1
[root@oradb30 media]# jobs
[1]+ Running scp -r Disk1/ 192.168.1.31:/u01/media/ &查看任务运行状态和父进程号:[root@oradb30 media]# ps -ef|grep scp
root 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.测试会话中断,任务继续运行不受影响[root@oradb30 media]# exit
logout
Last login: Thu Jan 5 05:19:50 2017 from 192.168.1.198
[root@oradb30 ~]#
[root@oradb30 ~]#
[root@oradb30 ~]#
[root@oradb30 ~]# ps -ef|grep scp
root 12704 1 0 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发现scp任务继续运行,没有因为会话断开而中断,父进程号变为1。如果有其他任务需要使用nohup后台运行,但执行时却忘记了使用nohup,也可以参照此方法进行设置。如果配置好ssh无密码登陆,也可以直接 nohup scp .. & 执行。