Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can I doesn't use popt alias file for rsync, while use the alias function in-line/in-place with the rsync command?

112 views
Skip to first unread message

Hongyi Zhao

unread,
Oct 27, 2012, 12:22:10 AM10/27/12
to
Hi all,

See the following usages of rsync:

$ cat /home/werner/.popt
rsync alias -Z --no-p --no-g --chmod=ugo=rwX

$ rsync -avZ --temp-dir=/tmp /media/cdrom/pool/ /home/werner/Desktop/111/

Here, I use the .popt file defined a alias option for rsync and then
invoke it with the alias -Z option. I want to know is it possible to
using the alias function without using the .popt alias file, say, just by
using the in-line/in-place redefinitions in-line/in-place within the rsync
commands?

Regards

Ben Bacarisse

unread,
Oct 27, 2012, 3:44:55 PM10/27/12
to
I can't follow what you want. An example might help.

--
Ben.

Hongyi Zhao

unread,
Oct 28, 2012, 11:31:15 AM10/28/12
to
On Sat, 27 Oct 2012 20:44:55 +0100, Ben Bacarisse wrote:

> I can't follow what you want. An example might help.

I mean without setting these options using the popt file, while using it
in, say, the ssh shell sript. With this way, it can let me obtain the
less script files for one job.

Regards

Ben Bacarisse

unread,
Oct 28, 2012, 5:26:07 PM10/28/12
to
That's not an example -- I still don't follow.

Part of the problem is what you seem to be asking -- how to avoid using
the .popt file -- seems to be too simple to be the actual problem. If
that's all you want to do, just add the arguments that -Z aliases
directly.

--
Ben.

Hongyi Zhao

unread,
Oct 28, 2012, 10:13:09 PM10/28/12
to
On Sun, 28 Oct 2012 21:26:07 +0000, Ben Bacarisse wrote:

> Part of the problem is what you seem to be asking -- how to avoid using
> the .popt file -- seems to be too simple to be the actual problem. If
> that's all you want to do, just add the arguments that -Z aliases
> directly.

Let me give more detailed of my topic:

In my case, I first use the /home/werner/.popt file to define the alias -
Z as follows:

$ cat /home/werner/.popt
rsync alias -Z --no-p --no-g --chmod=ugo=rwX

Then I run rsync with the alias -Z like this:

$ rsync -avZ --temp-dir=/tmp /media/cdrom/pool/ /home/werner/Desktop/111/

Now, suppose I want to do some more complicated job including the above
codes in it, I think it's a more easier way first define the
alias_varialbe in the script then invoke it by using rsync command in the
same script. I just want to know how to do the above things like this
way.

BTW, as you have pointed that, we can simply invoke the rsync like for my
purpose:

rsync -av --no-p --no-g --chmod=ugo=rwX --temp-dir=/tmp /media/cdrom/
pool/ /home/werner/Desktop/111/

But for a more complicated case, say, I want to do server different rsync
jobs with different alias options in one script, according to the
described method here, I must define all of the alias options in /home/
werner/.popt, in this way, I must remember all of the these definitions
in mind when I want to invoke them. While if I can define these alias
options in-place of the shell script which use all of these alias
options, I think it will be more convenient to use.

Regards

Ben Bacarisse

unread,
Oct 28, 2012, 10:43:54 PM10/28/12
to
The trouble is still that I can't see the problem. You've explained it
in such general terms that is sounds trivial -- just write the various
rsync commands and select one using an argument to the script.

Please give me an example. Show me what you do now using .popt and
explain how that should be made simpler.

--
Ben.

Hongyi Zhao

unread,
Oct 29, 2012, 12:30:27 AM10/29/12
to
On Mon, 29 Oct 2012 02:43:54 +0000, Ben Bacarisse wrote:

> The trouble is still that I can't see the problem. You've explained it
> in such general terms that is sounds trivial -- just write the various
> rsync commands and select one using an argument to the script.
>
> Please give me an example. Show me what you do now using .popt and
> explain how that should be made simpler.

As far as the current things I've done, such complex case is not the
case. But I think I will meet them in some time ;-)

Say, for in a shell script, I think the following method will be more
readable:

---------------
arg1=--no-p --no-g --chmod=ugo=rwX
...
rsync -av $arg1 --temp-dir=/tmp /media/cdrom/pool/ /home/werner/
Desktop/111/
----------------

Regards

Hongyi Zhao

unread,
Oct 29, 2012, 12:44:03 AM10/29/12
to
On Mon, 29 Oct 2012 04:30:27 +0000, Hongyi Zhao wrote:

> arg1=--no-p --no-g --chmod=ugo=rwX
...

Sorry, should like this:

arg1="--no-p --no-g --chmod=ugo=rwX"

> rsync -av $arg1 --temp-dir=/tmp /media/cdrom/pool/ /home/werner/
> Desktop/111/

Regards

Dave Gibson

unread,
Oct 29, 2012, 6:20:05 AM10/29/12
to
Hongyi Zhao <hongy...@gmail.com> wrote:
> On Sun, 28 Oct 2012 21:26:07 +0000, Ben Bacarisse wrote:
>
>> Part of the problem is what you seem to be asking -- how to avoid using
>> the .popt file -- seems to be too simple to be the actual problem. If
>> that's all you want to do, just add the arguments that -Z aliases
>> directly.
>
> Let me give more detailed of my topic:
>
> In my case, I first use the /home/werner/.popt file to define the alias -
> Z as follows:
>
> $ cat /home/werner/.popt
> rsync alias -Z --no-p --no-g --chmod=ugo=rwX
>
> Then I run rsync with the alias -Z like this:
>
> $ rsync -avZ --temp-dir=/tmp /media/cdrom/pool/ /home/werner/Desktop/111/
>
> Now, suppose I want to do some more complicated job including the above
> codes in it, I think it's a more easier way first define the
> alias_varialbe in the script then invoke it by using rsync command in the
> same script. I just want to know how to do the above things like this
> way.

Short answer, "No."

Option aliases are implemented by libpopt, to define an alias it is
necessary to address libpopt. The only way to do that (for rsync) is to
use popt's default configuration files.

Ben Bacarisse

unread,
Oct 29, 2012, 6:50:15 AM10/29/12
to
Hongyi Zhao <hongy...@gmail.com> writes:

> On Mon, 29 Oct 2012 02:43:54 +0000, Ben Bacarisse wrote:
>
>> The trouble is still that I can't see the problem. You've explained it
>> in such general terms that is sounds trivial -- just write the various
>> rsync commands and select one using an argument to the script.
>>
>> Please give me an example. Show me what you do now using .popt and
>> explain how that should be made simpler.
>
> As far as the current things I've done, such complex case is not the
> case. But I think I will meet them in some time ;-)

Ah. That may explain why I can't see the problem -- you don't yet no
that there will be one.

BTW, I would avoid using .popt defined alias options in a script. You
want the script to stand alone and making it depend on another file is
bound to be confusing; I support your objective, I just don't see the
problem.

> Say, for in a shell script, I think the following method will be more
> readable:
>
> ---------------
> arg1=--no-p --no-g --chmod=ugo=rwX
> ...
> rsync -av $arg1 --temp-dir=/tmp /media/cdrom/pool/ /home/werner/
> Desktop/111/
> ----------------

That's more readable than using options defined in another file, but I
don't think it's more readable than just writing out the options. You
need to take care when options contain characters that need quoting, but
that's not a common situation.

--
Ben.

Hongyi Zhao

unread,
Oct 30, 2012, 4:54:15 AM10/30/12
to
On Mon, 29 Oct 2012 10:20:05 +0000, Dave Gibson wrote:

> Short answer, "No."
>
> Option aliases are implemented by libpopt, to define an alias it is
> necessary to address libpopt. The only way to do that (for rsync) is to
> use popt's default configuration files.

As you can see in this topic discussed by me and Ben, I don't think the
way implemented by rsync is a good idea ;-(

Regards

Ben Bacarisse

unread,
Oct 30, 2012, 7:57:15 AM10/30/12
to
What do you mean? I don't see anything wrong at all. That was part of
the trouble I had -- I could not see what problem you were trying to
solve.

--
Ben.

Dave Gibson

unread,
Oct 30, 2012, 7:47:24 PM10/30/12
to
I think he wants to define popt aliases in the shell.

Something like

$ poptalias rsync -Z --arg1 --arg2

Then entering

$ rsync -aZ foo bar

would become

$ rsync -a --arg1 --arg2 foo bar

Ben Bacarisse

unread,
Oct 30, 2012, 11:09:11 PM10/30/12
to
You may be right. I asked three times for an example and someone else
provides it! Just another day on Usenet.

--
Ben.

Dave Gibson

unread,
Oct 31, 2012, 5:26:52 AM10/31/12
to
Hongyi Zhao <hongy...@gmail.com> wrote:

> In my case, I first use the /home/werner/.popt file to define the alias -
> Z as follows:
>
> $ cat /home/werner/.popt
> rsync alias -Z --no-p --no-g --chmod=ugo=rwX
>
> Then I run rsync with the alias -Z like this:
>
> $ rsync -avZ --temp-dir=/tmp /media/cdrom/pool/ /home/werner/Desktop/111/
>
> Now, suppose I want to do some more complicated job including the above
> codes in it, I think it's a more easier way first define the
> alias_varialbe in the script then invoke it by using rsync command in the
> same script. I just want to know how to do the above things like this
> way.
>
> BTW, as you have pointed that, we can simply invoke the rsync like for my
> purpose:
>
> rsync -av --no-p --no-g --chmod=ugo=rwX --temp-dir=/tmp /media/cdrom/
> pool/ /home/werner/Desktop/111/
>
> But for a more complicated case, say, I want to do server different rsync
> jobs with different alias options in one script, according to the
> described method here, I must define all of the alias options in /home/
> werner/.popt, in this way, I must remember all of the these definitions
> in mind when I want to invoke them. While if I can define these alias
> options in-place of the shell script which use all of these alias
> options, I think it will be more convenient to use.

Modify rsync to allow a popt initialisation file to be specified in an
environment variable. Use like this:

echo "alias rsync -Z --no-p --no-g --chmod=ugu=rwX" > poptrc1
RSYNC_POPTRC=poptrc1 rsync -aZv ...

echo "alias rsync -Z --chmod=ugu=rwX" > poptrc2
RSYNC_POPTRC=poptrc2 rsync -aZ ...

# to ignore system popt rc files
RSYNC_POPTRC=/dev/null rsync ...

and so on.

The following patch (between #v+ and #v-) contains tab characters. You
may need to use patch's -l (that's a lower-case L) argument if they are
converted to spaces in transit.

As usual, if this breaks you get to keep all the pieces.

#v+
--- rsync-3.0.9/options.c.orig 2011-09-13 23:41:26.000000000 +0100
+++ rsync-3.0.9/options.c 2012-10-31 09:22:38.000000000 +0000
@@ -898,6 +898,7 @@
const char *arg, **argv = *argv_p;
int argc = *argc_p;
int opt;
+ const char *rcf;

if (ref && *ref)
set_refuse_options(ref);
@@ -921,8 +922,12 @@
if (pc)
poptFreeContext(pc);
pc = poptGetContext(RSYNC_NAME, argc, argv, long_options, 0);
- if (!am_server)
- poptReadDefaultConfig(pc, 0);
+ if (!am_server) {
+ if ((rcf = getenv("RSYNC_POPTRC")))
+ poptReadConfigFile(pc, rcf);
+ else
+ poptReadDefaultConfig(pc, 0);
+ }

while ((opt = poptGetNextOpt(pc)) != -1) {
/* most options are handled automatically by popt;
#v-

Hongyi Zhao

unread,
Nov 4, 2012, 11:08:33 PM11/4/12
to
Oh, wonderful idea. This is a real unixer/linuxer should do ;-)

Regards
0 new messages