Re: Using sudo to write to a file as root from a script

2013-08-09 Thread Nobody
On Fri, 09 Aug 2013 21:12:20 +0100, Nobody wrote: > Try: > > command = ['sudo', 'tee', config_file] > p = subprocess.Popen(command, stdout=subprocess.PIPE, > stderr=subprocess.PIPE) > out, _ = p.communicate('channel') Oops; you also need stdin=subprocess.PIPE. -- http://mail.python.org/m

Re: Using sudo to write to a file as root from a script

2013-08-09 Thread Nobody
On Thu, 08 Aug 2013 23:11:09 -0500, Adam Mercer wrote: > 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: > command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file] You can't create a pipeline like this. All

Re: Using sudo to write to a file as root from a script

2013-08-09 Thread David
On 9 August 2013 23:21, Adam Mercer wrote: > On Thu, Aug 8, 2013 at 11:47 PM, David wrote: > >> At a quick glance, I have a couple of suggestions. >> >>> command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file] >> >> sudo doesn't work like this. It doesn't read from standard input. Yo

Re: Using sudo to write to a file as root from a script

2013-08-09 Thread Chris Angelico
On Fri, Aug 9, 2013 at 2:50 PM, Adam Mercer wrote: > On Fri, Aug 9, 2013 at 8:42 AM, Antoon Pardon > wrote: > >> That is probably beside the point. I suspect Adam is just giving a >> minimal example to show the kind of thing he is trying to do. >> >> Nit picking the specific example instead of ad

Re: Using sudo to write to a file as root from a script

2013-08-09 Thread Antoon Pardon
Op 09-08-13 06:11, Adam Mercer schreef: > 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',

Re: Using sudo to write to a file as root from a script

2013-08-09 Thread Adam Mercer
On Fri, Aug 9, 2013 at 8:42 AM, Antoon Pardon wrote: > That is probably beside the point. I suspect Adam is just giving a > minimal example to show the kind of thing he is trying to do. > > Nit picking the specific example instead of advising on the problem > is likely to be less than helpful. I

Re: Using sudo to write to a file as root from a script

2013-08-09 Thread Adam Mercer
On Fri, Aug 9, 2013 at 8:29 AM, Chris Angelico wrote: > You shouldn't need to use 'echo' here. Just provide tee with the text > on its standard input, and don't bother with the pipe at all. Thanks, that's much better! Cheers Adam -- http://mail.python.org/mailman/listinfo/python-list

Re: Using sudo to write to a file as root from a script

2013-08-09 Thread Antoon Pardon
Op 09-08-13 15:29, Chris Angelico schreef: > On Fri, Aug 9, 2013 at 2:21 PM, Adam Mercer wrote: >> command="echo -n %s | sudo tee %s > /dev/null" % (channel, config_file) >> > > You shouldn't need to use 'echo' here. Just provide tee with the text > on its standard input, and don't bother with th

Re: Using sudo to write to a file as root from a script

2013-08-09 Thread Chris Angelico
On Fri, Aug 9, 2013 at 2:21 PM, Adam Mercer wrote: > command="echo -n %s | sudo tee %s > /dev/null" % (channel, config_file) > You shouldn't need to use 'echo' here. Just provide tee with the text on its standard input, and don't bother with the pipe at all. ChrisA -- http://mail.python.org/ma

Re: Using sudo to write to a file as root from a script

2013-08-09 Thread Adam Mercer
On Thu, Aug 8, 2013 at 11:47 PM, David wrote: > At a quick glance, I have a couple of suggestions. > >> command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_file] > > sudo doesn't work like this. It doesn't read from standard input. You > need to supply the command as an argument to sud

Re: Using sudo to write to a file as root from a script

2013-08-09 Thread ishish
Am 09.08.2013 05:47, schrieb David: On 9 August 2013 14:11, Adam Mercer wrote: 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: [...] At a quick glance, I have a couple of suggestions. command = ['echo', '-n', ch

Re: Using sudo to write to a file as root from a script

2013-08-08 Thread David
On 9 August 2013 14:11, Adam Mercer wrote: > > 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: [...] At a quick glance, I have a couple of suggestions. > command = ['echo', '-n', channel, '|', 'sudo', 'tee', config_

Re: Using sudo to write to a file as root from a script

2013-08-08 Thread Denis McMahon
On Thu, 08 Aug 2013 23:11:09 -0500, Adam Mercer wrote: > 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', channe

Using sudo to write to a file as root from a script

2013-08-08 Thread Adam Mercer
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, stdo