Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script fails on ubuntu sh #45

Closed
rafaelmuylaert opened this issue Jan 30, 2014 · 5 comments
Closed

Script fails on ubuntu sh #45

rafaelmuylaert opened this issue Jan 30, 2014 · 5 comments

Comments

@rafaelmuylaert
Copy link
Contributor

When trying to run the script on a ubuntu box I get the following error:

sh: 27084: Syntax error: "fi" unexpected (expecting "then")

I understand it happens on this line:

  • rsync --dry-run \
  •    -auvzxi --delete $RSYNC_OPTS --exclude "/$DOT_DIR" --exclude-from "$TMP_DIR/fetch-exclude" $USER_RULES $REMOTE/ . \
    
  •  | grep "^[ch<>\.\*][f]\|\*deleting" | sed "s:^\S*\s*::" | sed "s:\(.*\):if [ -f \"\1\" ]; then cp --parents \"\1\" $DOT_DIR/backups/$TIMESTAMP; fi:" | sh || die "BACKUP"
    

apparently sh is not accepting nicely what sed feeds him... I tried to change the code to use

sed "s:(.*):test -f "\1" && cp --parents "\1" $DOT_DIR/backups/$TIMESTAMP:"

but that won't work nicely either...

Anyone has had the same problem?

@rafaelmuylaert
Copy link
Contributor Author

I got it.

Sed escapes the single quotes well, but the script crashes if it finds a back tick.

adding another sed to strip quotes out of the filenames did the job.

| grep "^[ch<>.*][f]|deleting" | sed "s:^\S_\s_::" | sed -ne 's/\d96\d39//gp' | sed "s:(.):if [ -f "\1" ]; then cp --parents "\1" $DOT_DIR/backups/$TIMESTAMP; fi:" | sh || die "BACKUP"

@torfason
Copy link
Collaborator

So am I correct in understanding that the issue was caused by back ticks in
filenames? If so, nice detective work, and some nice sedding ...

If that is the case, and you strip them from the filenames, what happens to
the files then? It seems to me that the "if []" then looks for a filename
without backtick, does not find it, and then does not back it up. Correct?

Nevertheless, if everything else in bitpocket then moves along without
issue, this might still be a candidate for application, since it would move
bitpocket from (a) breaking on back ticks in file names to (b) not backing
files with back ticks in their names up correctly. A note on that issue
should probably be added somewhere in that case.

On Thu, Jan 30, 2014 at 8:23 PM, rafaelmuylaert notifications@github.comwrote:

I got it.

Sed escapes the single quotes well, but the script crashes if it finds a
back tick.

adding another sed to strip quotes out of the filenames did the job.

| grep "^[ch<>.][f]|deleting" | sed "s:^\S\s::" | sed -ne
's/\d96\d39//gp' | sed "s:(.*):if [ -f "\1" ]; then cp --parents "\1"
$DOT_DIR/backups/$TIMESTAMP; fi:" | sh || die "BACKUP"


Reply to this email directly or view it on GitHubhttps://github.com//issues/45#issuecomment-33729035
.

@torfason
Copy link
Collaborator

Looks very nice!

On Fri, Jan 31, 2014 at 1:04 AM, rafaelmuylaert notifications@github.comwrote:

this should do it:

rsync -auvzxi --delete --dry-run /home/rafael/rsync/de/
/home/rafael/rsync/para | grep "^[ch<>.][f]|deleting" | sed "s:^\S\s::"
| sed 's:\d96:`:g' | sed "s:(.*):if [ -f "\1" ]; then cp --parents
"\1" /home/rafael/rsync/para/backups; fi:" | sh


Reply to this email directly or view it on GitHubhttps://github.com//issues/45#issuecomment-33753002
.

@ku1ik
Copy link
Owner

ku1ik commented Feb 5, 2014

This can be closed too, right?

@rafaelmuylaert
Copy link
Contributor Author

Also Yes :D

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants