Operating System - HP-UX
1754016 Members
7603 Online
108811 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