Rsync script problem
Hi all,
I am trying to write a script that syncs files from source to destination. I have one centralized server that can ssh to any servers without pw. Now when I run the script, it can ssh to source server perfectly fine, but you need to enter password for destination server. Was wondering how I can clean this up before I start using case statements Below is a sample I wrote #!/bin/bash #This scripts syncs shit echo "Type in ID: " read ID echo "Type in Server : " #source server read S echo "Type in Destination Server: " read DS if [ $S == 9 ]; then ssh -t "root@"$S"webserver1" "rsync -av /home/rlui/"$ID "root@"$DS"webserver2:/home/rlui/"; ssh -t "root@"$S"webserver1" "rsync -av /home/rlui/tmp/"$ID "root@sl"$DS"webserver2:/home/rlui/tmp/" exit 1 where S and DS are cluster numbers I apologize in advance if I am not clear on anything |
Your server is not sshing to $S and $DS, your server is only sshing to $S and then telling $S to ssh to $DS. $S needs to be able to ssh into $DS without a password if you want it to work as written.
I do not believe rsync will allow you to sync between two remote systems without a direct ssh connection between them. You'll either need to set up ssh keys between your source and destination servers and use your code as-written, or do the sync in two steps using your centralized server as a neutral 3rd party: rsync -av root@$S:/dir $S/dir rsync -av $S/dir root@$DS:/dir |
thanks,
I was just thinking about setting up ssh keys between the two source and destination servers. And I think the man page for rsync specified that you cannot sync between two remotes. Besides that, I don't know any other way to sync between two remote servers without pw prompt. This is so that if there are any big moves, I don't want to be up all night watching the progress of it. |
thanks suicidaleggroll ->
I am now experimenting with ssh-keys and modifying my script a bit I am now playing with this line ssh -t "root@sl"$SL"svc1" `rsync -e "ssh -l /root/.ssh/fileserver" -av` "/home/rlui/"$PLID "root@sl"$DSL"svc2:/home/rlui/"; I think my quotes might be wrong, will let you know when this works |
I solved it
I figured out that my way of doing it was pretty stupid. My senior took a look and is now fixed. I did end up using new ssh-keys however but I did not need to use if statements since I'm already passing on variables when I established read now the script is #!/bin/bash #This scripts syncs shit echo "Type in ID: " read ID echo "Type in Server : " #source server read S echo "Type in Destination Server: " read DS ssh "root@"$S"webserver1" "rsync -e 'ssh -i /root/.ssh/blah' -av /home/rlui/"$ID "root@"$DS"webserver2:/home/rlui/"; ssh "root@"$S"webserver1" "rsync -e 'ssh -i /root/.ssh/blah' -av /home/rlui/tmp/"$ID "root@sl"$DS"webserver2:/home/rlui/tmp/" once again thanks suicidal! |
Good job! Glad you got it running.
If you feel the question has been solved, please mark the thread as solved using the "Thread Tools" at the top of the page. |
All times are GMT -5. The time now is 01:59 PM. |