I wrote a simple script to backup a bunch of folders from one place to another over my LAN using rsync.
Although this works, I now want to change it so it backs up the same folder set to TWO places (or more in the future).
For now, I have literally copied and pasted the rsync commands (and in the second iteration, changed the destination server) as per the example below:-
copy folder 1 to server1
copy folder 2 to server1
...
copy folder N to server1
copy folder 1 to server2
copy folder 2 to server2
...
copy folder N to server2
Is there a way using SH script to do arrays & loops so it would be:-
server_array(0) = "server1"
server_array(1) = "server2"
for each item in server_array
copy folder 1 to item
copy folder 2 to item
...
copy folder N to item
next item
That way, if I change the list of folders to copy, I don’t need to make lots of changes, I just make one change (in the main loop).
Thank you for your time in reading this and any ideas you may have to help me
Sure… ‘for’ loops (like many others) are valid. For example:
<code interpreter="/bin/bash">
for i in a b c d e f; do echo $i; done
</code>
Good luck.
badger fruit wrote:
> Hello
>
> I wrote a simple script to backup a bunch of folders from one place to
> another over my LAN using rsync.
>
> Although this works, I now want to change it so it backs up the same
> folder set to TWO places (or more in the future).
>
> For now, I have literally copied and pasted the rsync commands (and in
> the second iteration, changed the destination server) as per the example
> below:-
>
>
> Code:
> --------------------
>
> copy folder 1 to server1
> copy folder 2 to server1
> …
> copy folder N to server1
>
>
> copy folder 1 to server2
> copy folder 2 to server2
> …
> copy folder N to server2
>
> --------------------
>
>
> Is there a way using SH script to do arrays & loops so it would be:-
>
>
> Code:
> --------------------
>
> server_array(0) = “server1”
> server_array(1) = “server2”
>
> for each item in server_array
> copy folder 1 to item
> copy folder 2 to item
> …
> copy folder N to item
> next item
>
> --------------------
>
>
> That way, if I change the list of folders to copy, I don’t need to make
> lots of changes, I just make one change (in the main loop).
>
> Thank you for your time in reading this and any ideas you may have to
> help me
>
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/