Operating System - HP-UX
1827249 Members
2705 Online
109716 Solutions
New Discussion

Copying files from one server to another on regular bases

 
SOLVED
Go to solution
Salman Ahmed Qureshi
Frequent Advisor

Copying files from one server to another on regular bases

Hi,
I have an HP Unix 11.11 server let say server A and another server B. On hourly bases, i want to copy some friles created on server A, on to the server B. Can anyone tell me what would be the best method and how could i accomplish this taks.
1. On which server should i schedule the cron job?
2. Which command would i use in the script which will copy files from server A to the server B (ftp, scp etc).
3. How the script will look like which will perform this taks.
I am very new in HP so i am not sure how to do this.
Thanks

Salman
22 REPLIES 22
Richard Hepworth
Esteemed Contributor

Re: Copying files from one server to another on regular bases

Salman,

I'd use scp to copy the files in question. If you are going to run it via cron you're going to need to setup authentication for the user doing the copy...

- logon to server A as the user who will initiate the copy
- if no ssh public keys exist in ~/.ssh or ~/.ssh2 then use ssh-keygen
- add the contents on the .pub key to the authorized_keys file on serverB:~/.ssh
- use scp to test the transfer works without a password (on serverA scp /path/to/file serverB:/path/to/destination)

if it works schedule it via cron
Dennis Handly
Acclaimed Contributor

Re: Copying files from one server to another on regular bases

You may want to look at rsync, started from cron.
Ganesan R
Honored Contributor

Re: Copying files from one server to another on regular bases

Hi Salman,

Files which you are going to copy is same everytime, rsync would be best option. It will update only the modifications instead of copying the entire file everytime.

Files are going to be different you can go for other options like scp, rcp . You need to setup passwordless logins for scp as specified by Richard.
Best wishes,

Ganesh.
Salman Ahmed Qureshi
Frequent Advisor

Re: Copying files from one server to another on regular bases

Hi Rishard,
Your suggestion seems to be good in my environment. Can you please explain a bit about following two points

- if no ssh public keys exist in ~/.ssh or ~/.ssh2 then use ssh-keygen
How to perform this operation?

- add the contents on the .pub key to the authorized_keys file on serverB:~/.s
I also don't understand this, can you please explian this a bit.

To other people, thanks for your reply but i can't go for sync since every time files will be new.

Salman
Richard Hepworth
Esteemed Contributor
Solution

Re: Copying files from one server to another on regular bases

Salman,

- logon to serverA as user doing transfer
- ssh-keygen -t dsa
- cat ~/.ssh/id_dsa.pub (copy contents)
- logon to serverB as user doing transfer
- cd ~/.ssh
- vi authorized_keys (paste contents from key above)

regards,

Richard
Ganesan R
Honored Contributor

Re: Copying files from one server to another on regular bases

Hi Salman,

Other than generating public key and copy it to destination, you should set the proper permissions. Otherwise passwordless login will not work.

Make sure the following permissions are set in destination server(Server B in your case)

Home directory should have 755 permission (users home directory)
$HOME/.ssh directory should have 700 permission
$HOME/.ssh/authorized_keys file should have 600 permission
Best wishes,

Ganesh.
likid0
Honored Contributor

Re: Copying files from one server to another on regular bases

I would use rsync over scp. you can use ssh comunication with the rsync option --rsh=ssh, for example:

cd $SYNC_DIR ; $RSYNC_BIN -avtz --rsync-path=$RSYNC_BIN --rsh="ssh -l $USER" . $DEST:$SYNC_DIR

Take a look at rsync docs.
Windows?, no thanks
Salman Ahmed Qureshi
Frequent Advisor

Re: Copying files from one server to another on regular bases

Hi,
ssh-keygen is not present on my server. I tried to find out from the server but it is not there. What to do now and how to install this ssh-keygen so that i could go ahead.
Thanks
Richard Hepworth
Esteemed Contributor

Re: Copying files from one server to another on regular bases

Ganesan R
Honored Contributor

Re: Copying files from one server to another on regular bases

Hi Salman,

ssh-keygen is secure shell command.
You need to find if you have installed secure shell product on your server.

#swlist |grep -i secure
#swlist |grep -i ssh

If it is not installed you can install HP ported Secure Shell or openssh which is avialble in net.

HP secure shell can be downloaded from above link.

openssh is here.

http://www.openssh.com/
Best wishes,

Ganesh.
Salman Ahmed Qureshi
Frequent Advisor

Re: Copying files from one server to another on regular bases

hi,
Thanks, its working, but very very very slow. Why? FTP is quite fast. Can i make it fast like FTP? On my LAN, the transfer rate is 3MB per second
Thanks
Salman Ahmed Qureshi
Frequent Advisor

Re: Copying files from one server to another on regular bases

How to do this if i want to use ftp. Can anyone tell me what should i write in the script for using ftp command to do the same operation. I can provide password within that script for the usser which will be used to connect for files transfer using ftp.
Thanks
Richard Hepworth
Esteemed Contributor

Re: Copying files from one server to another on regular bases

Salman,

scp, sftp are always going to be slower than ftp due to the encryption.
You can write an ftp script including user/passwd information but this is not the best policy security wise.

You can use this:

ftp -n server <user username password
cd /directory
put file
bye
EOT
Malcolm Leckie
Occasional Advisor

Re: Copying files from one server to another on regular bases

Here is an extract from a script we use:

IPADDR="192.168.2.1"
USERNAME="remoteuser"
PASSORD="remotepassword"
SOURCEFILE="/home/username/file"
DESTFILE="/home/remoteuser/file"
(
ftp -vin <open $IPADDR
quote USER $USRNAME
quote PASS $PASSWORD
put $SOURCEFILE $DESTFILE
quit
END_SCRIPT
) | grep "226 Transfer complete." > /tmp/ftp$SRCFILE


The assignments for IPADDR, USERNAME, PASSWORD, SOURCEFILE and DESTFILE should be changed as appropriate. Please also note that the target directory structure needs to be in place (same restrictions as 'cp').


I would suggest that from a security point of view scp is a much better solution and should be used where possible.
Malcolm Leckie
Occasional Advisor

Re: Copying files from one server to another on regular bases

Apologies for almost repeating the posting from Richard - didn't see his response until after I had replied.

Malcolm
Salman Ahmed Qureshi
Frequent Advisor

Re: Copying files from one server to another on regular bases

Can "rcp" work without suplying any password just like "scp" works? If yes then how to setup this.
Thanks
Richard Hepworth
Esteemed Contributor

Re: Copying files from one server to another on regular bases

Salman,

Just create .rhosts in $HOME on the target server with:

sourceserver user

and then try rcp. With this in place it should not prompt for a password.

regards,

Richard
Dennis Handly
Acclaimed Contributor

Re: Copying files from one server to another on regular bases

>Richard: Just create .rhosts in $HOME on the target server with:

If your $HOME is over NFS, you can just list every machine in .rhosts with permission 600 and owner of the user:
machine1
...
Salman Ahmed Qureshi
Frequent Advisor

Re: Copying files from one server to another on regular bases

Hi,
Sourrce is ods
destination is devdb03
i have a user "oracle" on bother servers
i create .rhosts in /home/oracle/ which is home directory of user oracle and set permissions to 600. I created this on devdb03.
Now i am running rcp from ods-prim but facing error as follows.

$ rcp sqlnet.log devdb03:/home/oracle/
remshd: Login incorrect.


Please help thanks
Dennis Handly
Acclaimed Contributor

Re: Copying files from one server to another on regular bases

>Source is ods, destination is devdb03

Do you have both in .rhosts?

>i have a user "oracle" on both servers

Does it have the same numeric ID on both machines? Use: id

>I created this on devdb03.

What's in that file?

>$ rcp sqlnet.log devdb03:/home/oracle/
remshd: Login incorrect.

If your networking isn't set up correctly, you may have to use the FQDN and/or IP address in .rhosts.
Abid Iqbal
Regular Advisor

Re: Copying files from one server to another on regular bases

Create .rhosts file on / (root) with entry as follwos,
+ +
(# Plus sign the space and then plus sign)
save file
and run the rcp command.
Abid Iqbal
Regular Advisor

Re: Copying files from one server to another on regular bases

sorry, it is not root /
it is /home