Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52240

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!feeder1.cambriumusenet.nl!82.197.223.108.MISMATCH!feeder2.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.83.MISMATCH!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ramercer@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.030
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'root': 0.05; 'subject:file': 0.07; 'subject:script': 0.09; 'cheers': 0.12; 'adam': 0.16; 'all.': 0.16; 'variable': 0.18; 'trying': 0.19; 'seems': 0.21; 'command': 0.22; 'script': 0.25; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'work.': 0.31; 'anyone': 0.31; 'file': 0.32; 'subject:from': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'writes': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'channel': 0.39; 'to:addr:python.org': 0.39; 'offer': 0.62; 'anything.': 0.68; 'channel,': 0.84; 'subject:Using': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=5rvSD4iApK5/RCWjMYQrbSyqBCSzQrivIIKACyGbFOI=; b=GqQXleJTQDoQQIzbOtOCqH31F9snYNdj9TErWym6Dx7K0FVoTqrKr9YMfeW5s/yrYH XzqRAJhF71rEfWUdvRPSUgmkG25GX4ubzmb366hLC2IlCGLRNstZ8T2piEMNyoFVb2D6 CautZj6Rofbn9EMlpSKAC5RTTkd9xSFC0h+W+xwvPxz5xdSpjdA/WYpqkwzDll8OOtaB 4+vtMyS2LULFLTv10GmC7AEhOW2BvKdUtSIqxCK051N2DCFS4nE64byFJNB/TU7mHUNX 1MMPBX0D/rh4f3kIe6/09IFJK8HN6W1Kove/vAJypBSL1kEwdv7cRMyNhEExzApZRMTs /p6g==
X-Received by 10.224.53.196 with SMTP id n4mr9147289qag.104.1376021509657; Thu, 08 Aug 2013 21:11:49 -0700 (PDT)
MIME-Version 1.0
From Adam Mercer <ramercer@gmail.com>
Date Thu, 8 Aug 2013 23:11:09 -0500
Subject Using sudo to write to a file as root from a script
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.383.1376022002.1251.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1376022002 news.xs4all.nl 15999 [2001:888:2000:d::a6]:48038
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:52240

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Using sudo to write to a file as root from a script Adam Mercer <ramercer@gmail.com> - 2013-08-08 23:11 -0500
  Re: Using sudo to write to a file as root from a script Denis McMahon <denismfmcmahon@gmail.com> - 2013-08-09 04:36 +0000
  Re: Using sudo to write to a file as root from a script Nobody <nobody@nowhere.com> - 2013-08-09 21:12 +0100
    Re: Using sudo to write to a file as root from a script Nobody <nobody@nowhere.com> - 2013-08-09 21:16 +0100

csiph-web