How to use rsync to invoke a shell?

Ah, okay.

Notice how there's no network attempts, no network traffic at all? In fact, the phrase "local transfer" shows up. There's no attempt to "contact the other system" so your -e option is being ignored! Bummer, huh?

But change it to this:

rsync -e "sh shell.sh" file1 localhost:/tmp

And you'll get the execution you desire. (As I pointed out in my first post, you'll get an error from the local rsync client because the server isn't talking the right protocol — it's just a shell script, after all! Oh, and you'll need the script in your home directory or "sh shell.sh" won't be able to find it.)

Figuring out how to get your script to forward the request to the proper backend so the local client doesn't error out is left as an exercise for the reader. :wink: (But I'll be here to help.)

Oh, and another hint: embedding quotes inside a filename and then using a wildcard will never work, as I mentioned previously — you can't be adding eval at the beginning of the command line to make it work because the typical user won't be doing that. But you can change it to a single word (ie, no spaces) so that the quotes aren't needed... (How do you change a script so that it can be executed directly, without needing sh?)

Have fun. I'll continue to monitor this thread if you have new questions related to this...

2 Likes