Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi,
I wrote a bash script for updating either my pc at home, or my pc at work (either one can be the target or source), but rsync always skips files resulting in the target directory having less files than the source. I basically don't know if there is a problem with my script, or if it's to do with rsync. I read that rsync doesn't behave properly when there are a lot of arguments, so I am only using two or three arguments, but I am stil getting that problem.
Here's the script I wrote:
Code:
#!/bin/bash
wa_zeus=warehouse
wa_home=warehouse
d[1]=bookmarks
d[2]=cics
d[3]=docs
d[4]=ga-codes
d[5]=linux
d[6]=manuals
d[7]=papers
d[8]=personal
d[9]=programming-c
d[10]=programming-fortran
zeus=xxxxxx@xxxxxxxxxx # username and ip of the remote pc
echo ' Choose which workstation to bring up to date:'
echo ' zeus --> home box, press 1'
echo ' home box --> zeus, press 2'
echo ' anything else exits this script.'; read choice
echo ' you chose' $choice
if [ "$choice" = 1 ]
then
for index in 1 2 3 4 5 6 7 8 9 10
do
echo
echo 'now rsync-ing '${d[index]}
rsync -r -z --delete --progress $zeus:/$wa_zeus/${d[index]}/* /$wa_home/${d[index]}/
done
echo 'All done!'
elif [ "$choice" = 2 ]
then
for index in 1 2 3 4 5 6 7 8 9 10
do
echo
echo 'now rsync-ing '${d[index]}
rsync -r -z --delete --progress /$wa_home/${d[index]}/* $zeus:/$wa_zeus/${d[index]}/
done
echo 'All done!'
else
echo 'You chose to exit'
fi
exit
By the way, does anybody know a quick way to write a "for" loop in bash that will recurse into directories? (wondering about this for another script of mine).
Well, the way you're doing your rsync looks right, although, that's not how I would have done it, so I can't be 100% sure of it's accuracy. Also, you might try putting a -x at the end of #!/bin/bash, that will give you more output when you run the command, you might be able to debug the issue that way.
Also, for your rsync, depending on what type of connection you have, you might want to include the --no-whole-file option.
As for your for loop, it's a kludge, but you could do something like:
for i in `ls */*.txt`; do echo $i;done
Something like that. Hopefully, someone will have a cleaner solution to that.
the reason I have done my rsync this way is because I don't want to syncronise all the directories, but only a few ones (which I can easily add/remove as values of the array), so I can't think of any other way of doing this easily. I could open and read a file containing the list of directories I want to synchronise, but this just adds complexity without real gains.
Could you please explain your suggestion for the for loop?
for i in `ls */*.txt`; do echo $i;done
I assume that the 'ls */*.txt' is a command and `pipes' to the value for `i' (correct?). I tried that ls command on a shell but it didn't work. I understand what `ls *.txt' does, but not the 'ls */*.txt'.
I've just found the problem... I was making a stupid mistake...
Basically the count from rsync for the files to be considered includes folders, but these aren't actually transfered rather than `created' in the target box. This is why the actual transfer number of files was always less than the total amount of `files' (ie files+directories)
Sure, I know what you mean with the folders and the like.
As for my quick script.
If you were to do an ls -l */*.txt, you'd get all the files that are in one level of folder down that end in *.txt, likewise you could */*/*.txt, which would go 2 folder levels down. Like I said, a kludge, the echo $i is just to tell you what the file is named in the iterative process of the script.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.