Operating System - HP-UX
1830204 Members
13130 Online
109999 Solutions
New Discussion

SCRIPT TO COPY DATA TO REMOTE SYSTEM

 
HP UNIX Professionals
Frequent Advisor

SCRIPT TO COPY DATA TO REMOTE SYSTEM

Hi Experts,

I want to copy some data (file and directory) from one server to remoter server through script.
Anybody help me to find out the scripts.

File:
===
/etc/XXX
/etc/YYY

Any model script for this please give me.

Thanks in Advance

VINAY
4 REPLIES 4
Kenan Erdey
Honored Contributor

Re: SCRIPT TO COPY DATA TO REMOTE SYSTEM

Hi,

you can use scp command with -r option to copy directories.

scp -r /etc/xxx ip:/etc/yyy

another way is using tar with ssh.


tar cvf - /etc/xxx | ssh ip "( cd /etc/yyy ; tar xvf - )"

or rsync with ssh, after creating public keys and distributing between servers

/usr/local/bin/rsync -avz -e ssh /etc/xxx/* user@target_ip:/etc/yyy/
Computers have lots of memory but no imagination
Larry Klasmier
Honored Contributor

Re: SCRIPT TO COPY DATA TO REMOTE SYSTEM

can you ssh/scp to the remote system? If so this is simple
scp /etc/XXX :/

Re: SCRIPT TO COPY DATA TO REMOTE SYSTEM

Hi VINAY,

I don't know what do you mean by "script", but if there are no special conditions, following can be used:

machineA# cd /etc/YYY
machineA# ssh machineB -n "cd /etc/XXX; tar cpf - ." | tar xvf -

cheers
Jan
mvpel
Trusted Contributor

Re: SCRIPT TO COPY DATA TO REMOTE SYSTEM

To have it automated with no password prompt, as is necessary for the script, you'll want to set up a public key pair for SSH/SCP.

You'd simply set no password on the private key, and insure that the permissions on the private key file are such that only the account associated with the script can read it. You can also restrict the key to support only this connection and command using options in the authorized_keys file.