LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-28-2015, 11:51 AM   #1
RayLui20
LQ Newbie
 
Registered: Jul 2013
Posts: 15

Rep: Reputation: Disabled
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
 
Old 04-28-2015, 12:12 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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

Last edited by suicidaleggroll; 04-28-2015 at 12:17 PM.
 
Old 04-28-2015, 12:41 PM   #3
RayLui20
LQ Newbie
 
Registered: Jul 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
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.
 
Old 04-29-2015, 10:55 AM   #4
RayLui20
LQ Newbie
 
Registered: Jul 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
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
 
Old 04-30-2015, 11:57 AM   #5
RayLui20
LQ Newbie
 
Registered: Jul 2013
Posts: 15

Original Poster
Rep: Reputation: Disabled
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!
 
Old 04-30-2015, 12:31 PM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,258

Rep: Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947Reputation: 1947
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need someone to look at rsync script JosephS Linux - Software 1 04-26-2015 06:50 PM
Rsync script help lleb Linux - Software 17 11-18-2011 04:30 PM
[SOLVED] Problem Getting rsync Script to run gjblackford Linux - General 7 02-25-2011 03:04 PM
how to write a script to know problem in network(rsync is going on) abhishekrahel Linux - Server 4 10-24-2008 01:37 AM
rsync script twantrd Programming 2 01-06-2005 06:46 AM


All times are GMT -5. The time now is 10:17 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration