0

I am a fresher and new to shell script. I have a file which contains file names. I want to rsync using that file names to a destination. I used for but not working. Below is the script :

basedir=/appshare/customerdata/

backupdir=/backup/

rsync=/usr/bin/rsync

ls -ltrh $basedir | awk {'print $9'} | grep .[0-9] > /tmp/include.txt

for line in /tmp/include.txt
do
    rsync -auvH $basedir$line --exclude-from /tmp/exclude.txt $backupdir
done

This script when run gives the following error :-

[root@practice Script]# ./customerdata 
sending incremental file list
rsync: change_dir "/appshare/customerdata//tmp" failed: No such file or directory (2)

sent 12 bytes  received 12 bytes  48.00 bytes/sec
total size is 0  speedup is 0.00
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1052) [sender=3.0.9]
2
  • cf. @krzyk's answer just adding three things: 1. if performance is an issue, call rsync fewer times with more input files at once by splicing the found files (and folder paths?) from basedir, 2. be aware of filenames with spaces, those should need some quoting so they are not mistaken as separate "things" when encountered by command as arguments, 3. Instead of the `cat /some/file`you can also use: $(cat /some/file) which might be good to know,(sometimes the backward single apostroph is not "at keyboard hand", or is typographically modified by a text "editor" ... Commented Jun 17, 2016 at 5:29
  • 1
    @Dilettant...Thanks for the tips. For folder name with space I have added the entry in both include and exclude files as "New\ Folder". It is working. Thanks again for the tips. Commented Jun 17, 2016 at 5:38

1 Answer 1

1

Line:

for line in /tmp/include.txt

Should be:

for line in `cat /tmp/include.txt`

Also, don't parse ls output, you can use globing from shell:

for line in $basedir/?[0-9]*;
do
    rsync -auvH $basedir$line --exclude-from /tmp/exclude.txt $backupdir
done
Sign up to request clarification or add additional context in comments.

2 Comments

@KalimullahGazi If you really think this is the correct answer mark it as such, please see meta.stackexchange.com/questions/5234/…
I have clicked on the "right" symbol. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.