I have to try and echo something to a file from python, but because fot eh content of what I want to write to this file, I seem to not be getting all of what I want into the file.

Here is what I WANT to echo to a file:
[ $(date +\%d) -eq $(echo $(cal) | awk '{print $NF}') ] &&

her is what shows up in the file:
[ $(date +\%d) -eq $(echo $(cal) | awk {print $NF}) ] &&

so if I have the variable:
mes = "[ $(date +\%d) -eq $(echo $(cal) | awk {print $NF}) ] && "+buCommand
os.popen("echo '"+mes+"'>>/etc/cron.d/"+mycronfile+";")

how do I KEPP my single quotes?

so if I have the variable:
mes = "[ $(date +\%d) -eq $(echo $(cal) | awk {print $NF}) ] && "+buCommand
os.popen("echo '"+mes+"'>>/etc/cron.d/"+mycronfile+";")

how do I KEPP my single quotes?

You put them in the mes variable :P

Above you have:

mes = "[ $(date +\%d) -eq $(echo $(cal) | awk {print $NF}) ] && "+buCommand
os.popen("echo '"+mes+"'>>/etc/cron.d/"+mycronfile+";")

I don't see any single quotes around the awk arguments.

If your real code has them and they still aren't showing up you could try to use a raw string, ie:

mes = r"[ $(date +\%d) -eq $(echo $(cal) | awk '{print $NF}') ] && "+buCommand
os.popen("echo '"+mes+"'>>/etc/cron.d/"+mycronfile+";")

Actually I do have the single quotes in there, but didn't seem to copy over corectly... the line is:
mes = "[ $(date +\%d) -eq $(echo $(cal) | awk '{print $NF}') ] &&
"

but that does not do the trick, instead I get:

[ $(date +\%d) -eq $(echo $(cal) | awk {print }) ] &&

So I added another set of singles:

mes = "[ $(date +\%d) -eq $(echo $(cal) | awk ''{print $NF}'') ] &&
"

and I get:

[ $(date +\%d) -eq $(echo $(cal) | awk {print $NF}) ] &&

Just missing the single quotes. This is happening from command line too when testing.

Here is what I WANT to echo to a file:
[ $(date +\%d) -eq $(echo $(cal) | awk '{print $NF}') ] &&

The brace, "}", is some kind of an escape character but I don't remember the particulars. Perhaps something like
mes = "$(date +\%d) -eq $(echo $(cal) | awk '{print $NF}" + "') ] &&"
or you may have to get ridiculous with something like the following as braces can be some sort of substitution; again I don't remember the particulars.
mes = "$(date +\%d) -eq $(echo $(cal) | awk '" + "{" + "print $NF" + "}" + "') ] &&"
would work. Also try a double brace, "}}" to see what happens as it appears to work as it should on my machine, Python 2.6.3 on Slackware64.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.