[Dirvish] pre & post scripts

Bjorn bl_dirvish at mblmail.net
Wed Oct 14 06:16:19 UTC 2015

Well, I did say "scripts," but that is not what the dirvish
documentation says.  For all four declarations (pre-server, pre-client,
post-client, post-server), the documentation refers to the argument as
shell_command.  And in the description it refers to commands multiple times.

There is also the question as to why the commands are being invoked with
"/bin/sh -c".  If it is always a single file script, you could just
invoke the script itself, without launching another shell process.

And as for "(S)", I take it that a single value can be a string with
multiple words - other Dirvish parameters accept multiple words.  It
still constitutes a single string.

I'll also note that currently dirvish will not work with a single
command that references any of the variables. I listed two commands in
my example because in the previous bug report (the link to which I
provided), one of the objections to the fix proposed at the time (adding
semicolons) could cause it to fail when executing multiple commands.
(And there are other related problems related to adding semicolons.)

On 10/13/2015 03:07 AM, Dave Howorth wrote:
> Bjorn wrote:
>> There appears to be a bug with the way the pre- and post- scripts are
>> executed.
> Note that this message says it is reporting an error about scripts, but
> then the detailed report does not use scripts, but instead uses explicit
> shell commands.
> If we look at http://dirvish.org/dirvish.conf.5.html we read:
> "Execute shell_command on client or server before or after making backup."
> Note singular, not plural wording and the option is marked with '(S)'
> meaning single occurrence, not multiple.
> I think the reason people don't run into this issue is that they use
> scripts. The documentation could be clearer that that is what is intended.
> Cheers, Dave
>> In subroutine scriptrun, a string is assembled with the shell invocation
>> (sh -c, by default), environment variables, command, and redirection.
>> The problem is that the environment variables are within the shell
>> invocation.  For example, if you to declare:
>> post-server: echo "DIRVISH_SERVER is ${DIRVISH_SERVER}"; echo
>> (Notes:
>> 	Yes, you can try the above on any dirvish profile or vault that doesn't
>> already have a post-server statement.
>> 	I've purposely used two distinct echo commands.  I just wanted to show
>> that my proposed solution works for multiple statements.)
>> You'll see in the resulting log file the following output:
>> The problem is that the environment variables (DIRVISH_SERVER,
>> DIRVISH_CLIENT, et al) are put after the /bin/sh -c invocation, not
>> before.  The resulting string is (using only a couple of environment
>> variables and omitting the redirection for illustration):
>> /bin/sh -c 'DIRVISH_SERVER=server.example.com
>> DIRVISH_CLIENT=client.example.com echo "DIRVISH_SERVER is
>> If you execute the above you will see it does not work as expected.  The
>> problem is that all the variables are expanded before execution of the
>> /bin/sh command.  Since the variables were not previously set, they
>> output as unset variables.
>> I believe the proper solution is to declare the variables before
>> invoking the shell.  So the example above would look like:
>> DIRVISH_SERVER=server.example.com DIRVISH_CLIENT=client.example.com
>> /bin/sh -c 'echo "DIRVISH_SERVER is ${DIRVISH_SERVER}"; echo
>> (You can also execute the above on a shell to see the results.)
>> Attached is the patch that I believe solves the problem; it merely
>> changes the placement of the $A{env} variable.
>> I noticed that quite some time ago, someone brought up the problem:
>> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=559660
>> The proposed solution was to put the script commands in a separate file,
>> and execute that.  That does work as a work-around, but I believe it
>> would be better to fix the dirvish script.
>> The ordering of environment variables in front of the command is
>> described in the bash man page, under "Simple Commands."
>> ------------------------------------------------------------------------
>> _______________________________________________
>> Dirvish mailing list
>> Dirvish at dirvish.org
>> http://www.dirvish.org/mailman/listinfo/dirvish
> _______________________________________________
> Dirvish mailing list
> Dirvish at dirvish.org
> http://www.dirvish.org/mailman/listinfo/dirvish

More information about the Dirvish mailing list