Python escaping sed and bash command with subprocess -
question:
how use sed python successfully? have run command on remote server list of comma delimited hosts. when ran bash want host1, host2, host3
here have:
process = subprocess.popen(["ssh $user@mychefserver knife search node "chef_environment:*" | grep -i "node name" | egrep -i "stuff|ruff" | uniq -u | sort -n | cut -d ":" -f 2 | sed -e 's/^[ \t]*//' | tr '\n' ', ' "], shell=false, stdout=pipe)
i know i'll have escape \n, \t, etc, i'm having trouble rest. whenever try run python script error invalid syntax though i've tried cornucopia of escapes.
you string quoting broken use "
inside double quoted string. have escape "
\"
. further note, of double quotes in command line can replaced single quotes '
. following code should work:
process = subprocess.popen(["ssh $user@mychefserver knife search node \"chef_environment:*\" | grep -i 'node name' | egrep -i 'stuff|ruff' | uniq -u | sort -n | cut -d':' -f 2 | sed -e 's/^[ \t]*//' | tr '\n' ', '"], shell=false, stdout=subprocess.pipe)
Comments
Post a Comment