0

I have a bash script that basically reads a file containing the names of files to ignore and executes an rsync command:

output="sudo rsync -avz"

# Read the file in parameter and fill the array named "array"
getArray() {
    i=0
    while read line # Read a line
    do
        output="$output --exclude '$line'"
        i=$(($i + 1))
    done < $1
}

getArray "/opt/ATP/Webapp/static/ignored_files.txt"
output="$output source/ dest/"
echo $output
echo `$output`

File listing files to ignore

forms.py
forms.pyc

This gives me the output command

sudo rsync -avz --exclude 'forms.py' --exclude 'forms.pyc' source/ dest/

However, this simply copies all files across from source folder to destination, without ignoring any files. If I copy and pasted that line in the shell, it would work fine and ignore the files.

Output from running from file

$ sudo sh data_migration.sh
sudo rsync -avz --exclude 'forms.py' --exclude 'forms.pyc' --exclude '' source/ dest/
sending incremental file list ./ __init__.py __init__.pyc admin.py admin.pyc forms.py forms.pyc lists.py lists.pyc models.py models.pyc tables.py urls.py urls.pyc views.py views.pyc wsgi.py 
sent 22155 bytes received 319 bytes 44948.00 bytes/sec total size is 60218 speedup is 2.68

Contents of destination folder

$ ls dest/
admin.py  admin.pyc  forms.py  forms.pyc  __init__.py  __init__.pyc  lists.py  lists.pyc  models.py  models.pyc  tables.py  urls.py  urls.pyc  views.py  views.pyc  wsgi.py

Output from running manually

$ sudo rsync -avz --exclude 'forms.py' --exclude 'forms.pyc' --exclude '' source/ dest/
$ sudo rsync -avz --exclude 'forms.py' --exclude 'forms.pyc' --exclude '' source/ dest/
sending incremental file list
./
__init__.py
__init__.pyc
admin.py
admin.pyc
lists.py
lists.pyc
models.py
models.pyc
tables.py
urls.py
urls.pyc
views.py
views.pyc
wsgi.py

sent 18398 bytes  received 281 bytes  37358.00 bytes/sec
total size is 50171  speedup is 2.69
Jon
  • 3,174
  • 11
  • 39
  • 57

0 Answers0