I'm trying to write a python 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?