On 12/14/2009 07:12 PM, Paul Slootman wrote:
> On Mon 14 Dec 2009, robert spitzenpfeil wrote:
>
>   
>> post-server: cd .. ; find ./tree -type f ! -name
>> "dirvish_md5sums-on_server.log" -exec md5sum {} \; | cat >
>> dirvish_md5sums-on_server.log ; ../magic.pl $DIRVISH_SRC ; scp -P 66
>> dirvish_md5sums-for_client.log r...@$dirvish_client:/tmp ; ssh -p 66
>> r...@$dirvish_client "md5sum -c /tmp/dirvish_md5sums-for_client.log
>>     
>>> /tmp/dirvish_md5sums-for_client.checked" ; scp -P 66
>>>       
>> r...@$dirvish_client:/tmp/dirvish_md5sums-for_client.checked . ; ssh
>> -p 66 r...@$dirvish_client "rm /tmp/dirvish_md5sums-for_client*";
>> find ./ -name "dirvish_md5sums*" -exec gzip {} \;
>>     
> Argh
>
> The problem is that by writing out all the shell commands on one line,
> is that only the first command will be run in the environment with the
> DIRVISH_* variables set. 
Aha, and where is that written down ? But I've verified it and it is
like it is.

> The rest of the commands will use the bash
> environment, which can't use the environment from the first commmand...
>
> Hence your proposed patch will help ONLY your situation. People that run
> a separate command will LOSE the variables!
>   
Because they will all be 'local' ?
> How about throwing all of that into a separate script, e.g. under
> /etc/dirvish/robertscript or whatever :-)  Let's write that out:
>
> cd ..
> find ./tree -type f ! -name "dirvish_md5sums-on_server.log" -exec md5sum {} 
> \; | cat > dirvish_md5sums-on_server.log
> ../magic.pl $DIRVISH_SRC
> scp -P 66 dirvish_md5sums-for_client.log r...@$dirvish_client:/tmp
> ssh -p 66 r...@$dirvish_client "md5sum -c /tmp/dirvish_md5sums-for_client.log 
> > /tmp/dirvish_md5sums-for_client.checked"
> scp -P 66 r...@$dirvish_client:/tmp/dirvish_md5sums-for_client.checked .
> ssh -p 66 r...@$dirvish_client "rm /tmp/dirvish_md5sums-for_client*"
> find ./ -name "dirvish_md5sums*" -exec gzip {} \;
>
>
> First a couple of comments:
> - command | cat > file
>   Better to do:
>   command > file
>   Why waste a pipe and a process?
>   
Never change a running system ;-)
> - find -exec command {} \;
>   Better to do:
>   find -print0 | xargs -0 command
>   This saves a lot of processes. Of course, if there are only a couple
>   of files that are matched then it doesn't matter so much.
>   
I thought xargs did fork off kids as well.

> - find ./tree
>   Why the ./ ?  find won't use "tree" anywhere else in the filesystem...
>   
I'm paranoid, never assume anything.
>   Why not ./././././tree ? :-)
>   Of course, perhaps something else in your commands may be expecting
>   the paths to have ./ prepended.
>   
Exactly.
> So the second line becomes:
> find tree -type f ! -name dirvish_md5sums-on_server.log -print0 | xargs -0 
> md5sum > dirvish_md5sums-on_server.log
>
> I'd change the last line to:
> gzip dirvish_md5sums*
>   
That assumes that gzip treats all the files individually. We're lucky it
does.
If I used 'zip' it wouldn't work.
> So put this in your script file:
>
> #!/bin/sh -e
> cd ..
> find tree -type f ! -name dirvish_md5sums-on_server.log -print0 | xargs -0 
> md5sum > dirvish_md5sums-on_server.log
> ../magic.pl $DIRVISH_SRC
> scp -P 66 dirvish_md5sums-for_client.log r...@$dirvish_client:/tmp
> ssh -p 66 r...@$dirvish_client "md5sum -c /tmp/dirvish_md5sums-for_client.log 
> > /tmp/dirvish_md5sums-for_client.checked"
> scp -P 66 r...@$dirvish_client:/tmp/dirvish_md5sums-for_client.checked .
> ssh -p 66 r...@$dirvish_client "rm /tmp/dirvish_md5sums-for_client*"
> gzip dirvish_md5sums*
>
> Do a chmod +x scriptfile to make it executable.
>   

I thought renaming it to scriptfile.exe would make it work.

I've been using linux since SuSE 5.2 I think, so I've come across that
one before. I'm glad you know of it too ;-)
But I'd use 'chmod u+x'.

> The -e makes the script stop as soon as any command fails, which is
> usually the safest option.
>   
Good to know.
> Now put:
> post-server: /etc/dirvish/scriptfile
>   
Why there ? What if I'm not root on that system ?
> in the config instead of that whole shebang, and I'm sure those
> environment variables will exist in that script, without the need to
> modify dirvish.
>
>
> Paul
>   

The bug can be closed. I think the dirvish docs should be amended with
respect to this environment variable behaviour.


Regards,

Robert




-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to