Home:ALL Converter>running system commands on linux using python?

running system commands on linux using python?

Ask Time:2012-02-17T01:56:52         Author:Lostsoul

Json Formatter

I'm wondering if someone can either direct me to a example or help me with my code for running commands on linux(centos). Basically, I am assuming I have a basic fresh server and want to configure it. I thought I could list the commands I need to run and it would work but I'm getting errors. The errors are related to nothing to make(when making thift).

I think this is because(I'm just assuming here) that python is just sending the code to run and then sending another and another and not waiting for each command to finish running(after the script fails, I check and the thrift package is downloaded and successfully uncompressed).

Here's the code:

#python command list to setup new server
import commands
commands_to_run = ['yum -y install pypy autocon automake libtool flex boost-devel gcc-c++  byacc svn openssl-devel make  java-1.6.0-openjdk git wget', 'service mysqld start',
                'wget http://www.quickprepaidcard.com/apache//thrift/0.8.0/thrift-0.8.0.tar.gz', 'tar zxvf thrift-0.8.0.tar.gz',
                'cd thrift-0.8.0', './configure', 'make', 'make install' ]


for x in commands_to_run:
    print commands.getstatusoutput(x)

Any suggestions on how to get this to work? If my approach is totally wrong then let me know(I know I can use a bash script but I'm trying to improve my python skills).

Author:Lostsoul,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/9316468/running-system-commands-on-linux-using-python
yy