fab-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Fab-user] Writing file with multiple lines to host?


From: Nick Sergeant
Subject: Re: [Fab-user] Writing file with multiple lines to host?
Date: Tue, 25 Nov 2008 19:15:50 -0500

Fabric is escaping any `$` character that isn't part of a variable, in
an effort to have Bash handle them correctly.

Ah, I was hoping Fabric would do that.

What I think is happening is, that bash is treating them as
environment variable interpolations, but since these variables are not
defined in your environment on the server, they evaluate to the empty
string, thus making it look like they just disappear.

That's exactly what I thought.

Try playing with the escaping; adding one or two back-slashes, or
removing the one you already have.

Here's some interesting tests:

###########################

Source:

def test():    
    run(""" echo "
        $var
        \$var
        \\$var
        $$var" | cat > test.txt
    """)
    run("cat test.txt")

###########################

Test 1 (without var name):

~/test > fab test
Fabric v. 0.0.9.
Running test...
Logging into the following hosts as admin:
    domain.com
[domain.com] run:  echo "
        $
        \$
        \$
        $$" | cat > test.txt
    
[domain.com] run: cat test.txt
[domain.com] out: 
[domain.com] out:         $
[domain.com] out:         $
[domain.com] out:         $
[domain.com] out:         12099
Done.

###########################

Test 2 (with var name):

~/test > fab test
Fabric v. 0.0.9.
Running test...
Logging into the following hosts as admin:
    domain.com
[domain.com] run:  echo "
        $var
        \$var
        \$var
        $$var" | cat > test.txt
    
[domain.com] run: cat test.txt
[domain.com] out: 
[domain.com] out:         
[domain.com] out:                         13721var
Done.

###########################

Very weird - it looks like the '$' is properly escaped unless it is followed by a non-whitespace character.

Oh, snap.  I threw in one more backslash:

###########################

def test(**kwargs):    
    run(""" echo "
        $var
        \$var
        \\\$var
        $$var" | cat > test.txt
    """)
    run("cat test.txt")

~/test > fab test
Fabric v. 0.0.9.
Running test...
Logging into the following hosts as admin:
    domain.com
[domain.com] run:  echo "
        $var
        \$var
        \\$var
        $$var" | cat > test.txt
    
[domain.com] run: cat test.txt
[domain.com] out: 
[domain.com] out:         
[domain.com] out:                 $var
[domain.com] out:         28196var
Done.

###########################

Looks like we have a winner!

Thanks!

Nick Sergeant
(315) 719-2047

On Nov 25, 2008, at 5:07 PM, Christian Vest Hansen wrote:

On Tue, Nov 25, 2008 at 9:13 PM, Nick Sergeant <address@hidden> wrote:
I'm trying to create a new file on the remote file system with some
dynamically generated content, like so:
run(""" echo "
       <?php
       \$db_url =
'mysqli://$(new_mysql_user):$(new_mysql_pass)@$(new_mysql_host)/$(new_mysql_db)';
       \$db_prefix = '';
       \$update_free_access = FALSE;
       ini_set('arg_separator.output',     '&amp;');
       ini_set('magic_quotes_runtime',     0);
       ini_set('magic_quotes_sybase',      0);
       ini_set('session.cache_expire',     200000);
       ini_set('session.cache_limiter',    'none');
       ini_set('session.cookie_lifetime',  2000000);
       ini_set('session.gc_maxlifetime',   200000);
       ini_set('session.save_handler',     'user');
       ini_set('session.use_only_cookies', 1);
       ini_set('session.use_trans_sid',    0);
       ini_set('url_rewriter.tags',        '');
       \$cookie_domain = '$(new_domain)';
       " | cat > $(prod_dir)/sites/$(new_domain)/settings.php
   """)
However, when the file is written, all of the PHP variable names are
removed.  Output:
<?php
\ = 'mysqli://blogsuser:address@hidden/blogsdomain';
\ = '';
\ = FALSE;
ini_set('arg_separator.output',     '&amp;');
ini_set('magic_quotes_runtime',     0);
ini_set('magic_quotes_sybase',      0);
ini_set('session.cache_expire',     200000);
ini_set('session.cache_limiter',    'none');
ini_set('session.cookie_lifetime',  2000000);
ini_set('session.gc_maxlifetime',   200000);
ini_set('session.save_handler',     'user');
ini_set('session.use_only_cookies', 1);
ini_set('session.use_trans_sid',    0);
ini_set('url_rewriter.tags',        '');
\ = 'blogs.domain.com';
I'm assuming Fabric is thinking those are variables.

Not quite. Notice how the `&amp;` survives.

Fabric is escaping any `$` character that isn't part of a variable, in
an effort to have Bash handle them correctly.

What I think is happening is, that bash is treating them as
environment variable interpolations, but since these variables are not
defined in your environment on the server, they evaluate to the empty
string, thus making it look like they just disappear.

What would be the best approach to tackle this?  I've tried a bunch of
alternative methods (using cat, touch, etc), with no luck.

Try playing with the escaping; adding one or two back-slashes, or
removing the one you already have.

I know it's a vague advice, but escaping through multiple layers of
programming and interpretation seems always to be an effort of trial
and error.

Thanks!
Nick Sergeant
www.nicksergeant.com
address@hidden
(315) 719-2047

_______________________________________________
Fab-user mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/fab-user





--
Venlig hilsen / Kind regards,
Christian Vest Hansen.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]