Using sudo to write to a file as root from a script
Adam Mercer
ramercer at gmail.com
Fri Aug 9 00:11:09 EDT 2013
Hi
I'm trying to write a script that writes some content to a file root
through sudo, but it's not working at all. I am using:
channel = 'stable'
config_file = '/opt/ldg/etc/channel.conf'
command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file]
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, _ = p.communicate()
But it seems as if this isn't doing anything.
I just want to write the contents of the variable channel to the file
/opt/ldg/etc/channel.conf. But whatever I try just doesn't work. Can
anyone offer any pointers?
Cheers
Adam
More information about the Python-list
mailing list