rsync git modified files with awk and sed Feb 15
Need to rsync modified files to a server? Try the following:
All you need to do is ensure that the base path set properly and modify the user@remote.server.com portion of the script and you’re all set!
Explanation after the break.
Here’s the breakdown:
git
Display modified files the same way svn status does – line by line with a symbol in front to designate type of change.
git status -s
This prints out the following:
M www/path/to/file
M www/another/path/to/file
awk
Piped with the git call above, this will strip out everything fron the line except for the file path.
awk '{print $2}'
This prints out the following:
www/path/to/file
www/another/path/to/file
sed
With the file paths piped in via the awk command, add the rsync around it with sed.
sed 's/\(.*\)/rsync -cav \1 user@remote.server.com:~\/\1/'
This prints out the following:
rsync -cav www/path/to/file user@remote.server.com:~/www/path/to/file
rsync -cav www/another/path/to/file user@remote.server.com:~/www/another/path/to/file
sh
Finally, we pipe the sed call into sh which executes it.
sh