LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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, 10:51 AM   #1
RayLui20
LQ Newbie
 
Registered: Jul 2013
Posts: 16

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, 11:12 AM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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 11:17 AM.
 
Old 04-28-2015, 11:41 AM   #3
RayLui20
LQ Newbie
 
Registered: Jul 2013
Posts: 16

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, 09:55 AM   #4
RayLui20
LQ Newbie
 
Registered: Jul 2013
Posts: 16

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, 10:57 AM   #5
RayLui20
LQ Newbie
 
Registered: Jul 2013
Posts: 16

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, 11:31 AM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

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



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 05:50 PM
Rsync script help lleb Linux - Software 17 11-18-2011 03:30 PM
[SOLVED] Problem Getting rsync Script to run gjblackford Linux - General 7 02-25-2011 02:04 PM
how to write a script to know problem in network(rsync is going on) abhishekrahel Linux - Server 4 10-24-2008 12:37 AM
rsync script twantrd Programming 2 01-06-2005 05:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:19 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
Open Source Consulting | Domain Registration