Script for copy&delete directory from one server to another

hatfani

New Member
Joined
Oct 21, 2019
Messages
1
Reaction score
0
Credits
0
Hey everyone,

I have 2 remote Servers: Server A and Server B.
On Server A I have a directory named: 'Example'
I need to copy 'Example' directory from Server A to Server B and then delete it from Server A (if there's a possibility to do it by one command it would be better of course).
I would like to create a script for those actions, I saw there are some options with scp/rsync commands.
I think that I need to configure ssh-key too so they'll do it automatically without the need of authentications all the time - would like to have more information about how I need to do that.

Thank you guys!
 


Hi,

Code:
sshpass -p user_a_password ssh user_a@server_a 'sshpass -p user_b_password scp -r /path/to/move user_b@server_b:/path/destination/

You can put something like this in a script file and have it run periodically with cron.
 

Members online


Latest posts

Top