LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-10-2012, 03:29 PM   #1
KroniK
LQ Newbie
 
Registered: Aug 2012
Posts: 13

Rep: Reputation: Disabled
Bash -- Rsync directory variable has a space


So I am writing a bash script to automatically rsync around 40 different directories to 40 other directories on another server.

If you want to read my whole script you can find it here: http://pastebin.com/uph49vHd

However the important bit is as follows:

Code:
 
for ((i=0; i<1; i++))
do
localpath="'/nusdata/staff/NUS/NUS/Systems/${kiskasys[$i]}'"
remotepath="/home/www/html/systems/${websys[$i]}"
rsync -rlptnvz -s "$localpath" -e "ssh -p 50014" "nusak@webserver:$remotepath/"
done
Where kiskasys is an array of directory names and websys is an array of corresponding directory names.

The problem is that kiskasys is full of directory names with spaces.

Now I can easily change how those directory names are put into the array, say by adding escaped spaces like '\ ' or by adding quotes around it etc but i have tried all different combinations of this and still have yet to make it work.

Here is an example of what the rsync command would look like if i didnt use variables:

Code:
rsync -rlptnvz -s "nusdata/staff/NUS/NUS/Systems/101 greenbrook/" -e "ssh -p 50014" "nusak@webserver:/foo/bar"
note that the only directory with spaces would be the local directory.

Any help on how to make this work would be appreciated!!

Thanks
 
Old 08-10-2012, 04:37 PM   #2
KroniK
LQ Newbie
 
Registered: Aug 2012
Posts: 13

Original Poster
Rep: Reputation: Disabled
Found the error.

the above is correct, i just needed to remove the single quotes in the localsys variable...
 
Old 08-11-2012, 08:49 AM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,561

Rep: Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939Reputation: 1939
Please mark as SOLVED once you have a solution.
 
  


Reply

Tags
bash, directory, rsync, spaces, variable


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
Bash: How do I read data from a variable while that variable is being populated? theaceoffire Programming 4 04-23-2010 02:29 PM
bash script: use the directory of the script file as variable? phling Linux - Newbie 12 01-16-2010 07:16 PM
Script to copy specific directory based on variable to folder with that variable name fluxburn Programming 7 01-07-2010 07:59 PM
How to get variable from text file into Bash variable mcdef Linux - Software 2 06-10-2009 01:15 PM
How do you assign a variable to be a variable file name in a directory? David_Elliott Programming 4 04-14-2009 10:19 AM


All times are GMT -5. The time now is 11:17 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration