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 ramer...@gmail.com 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

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 bouncingc...@gmail.com 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

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 ramer...@gmail.com 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 --

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 ramer...@gmail.com 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

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 ros...@gmail.com 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 --

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 antoon.par...@rece.vub.ac.be 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

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', 'tee',

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 ramer...@gmail.com wrote: On Fri, Aug 9, 2013 at 8:42 AM, Antoon Pardon antoon.par...@rece.vub.ac.be 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

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 ramer...@gmail.com wrote: On Thu, Aug 8, 2013 at 11:47 PM, David bouncingc...@gmail.com 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

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 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. --

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,

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', channel, '|',

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 ramer...@gmail.com 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',