Usually we use scp command to transfer a file from one server to another server. Say for example if we want to transfer 100GB file then best idea is to run at background.
But running scp at background has a problem which is "password". scp always prompt for a password which cannot be given in shell script. ( Check end of the post for other method to run as a shell script )
Here we will see a simple method to scp at background by providing password at the foreground.
**************************************** Step By Step Procedure ******************************************************
Source Server : host01
Source Path : /u01/backup/test.dmp Destination server : host02
Destination Path : /u02/test.dmp
#########################################
# 1) scp Command
#########################################
nohup scp /u01/backup/test.dmp host02:/u02/test.dmp > nohup.out 2>&1
=====================================================================================================================
#########################################
# 2) Run scp Command
#########################################
Once we run the above command it will prompt for Password, Input Password and then Press Ctrl + Z ( Now scp is stopped )
[oracle@host01 srini]$ nohup scp /u01/backup/test.dmp host02:/u02/test.dmp > nohup.out 2>&1
oracle@host02's password:
^Z
[1]+ Stopped nohup scp /u01/backup/test.dmp host02:/u02/test.dmp > nohup.out 2>&1
You have new mail in /var/spool/mail/oracle
[oracle@host01 srini]$
=====================================================================================================================
#########################################
# 3) Start the Process in Background
#########################################
Type "bg" command and scp process will start in background
[oracle@host01 srini]$ bg
[1]+ nohup scp /u01/backup/test.dmp host02:/u02/test.dmp > nohup.out 2>&1 &
[oracle@host01 srini]$
=====================================================================================================================
#########################################
# 4) Check if scp is running
#########################################
Type "jobs", it will show the scp job is running
[oracle@host01 srini]$ jobs
[1]+ Running nohup scp /u01/backup/test.dmp host02:/u02/test.dmp > nohup.out 2>&1 &
[oracle@host01 srini]$
=====================================================================================================================
#########################################
# 5) Run scp at Fore Ground
#########################################
Type "fg", it will show run the scp in foreground instead of background
[oracle@host01 srini]$ fg
nohup scp /u01/backup/test.dmp host02:/u02/test.dmp > nohup.out 2>&1
=====================================================================================================================
#########################################
# 6) Other Methods to run scp @ Background
#########################################
a) Using Expect Script
b) SSHPass
c) Establish ssh connectivity by generating keygen ( http://stepintooracledba.blogspot.com/2013/12/configure-ssh-manually-for-rac-4-node.html )
=====================================================================================================================
Comments Are Always welcome
=====================================================================================================================
No comments:
Post a Comment