我想知道是否有人能够为我提供示例或帮助我运行Linux(CentOS)上的命令。基本上,我假设我有一个基本的新服务器并想要配置它。我认为我可以列出需要运行的命令,但是我遇到了错误。这些错误与无法制作thift有关。我认为这是因为(我只是假设)Python只是发送要运行的代码,然后发送另一个代码,并且不等待每个命令完成运行(在脚本失败后,我检查并发现thrift包已下载并成功解压缩)。以下是代码:
#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)
有没有关于如何使这个工作的建议?如果我的方法完全错误,请让我知道(我知道我可以使用bash脚本,但我正在尝试提高我的Python技能)。
os
库中的system()
函数?(http://docs.python.org/library/os.html#os.system) - yasouser