[Dirvish] pre & post scripts

Dave Howorth dhoworth at mrc-lmb.cam.ac.uk
Tue Oct 13 10:07:14 UTC 2015

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

More information about the Dirvish mailing list