python控制进程在linux系统上运行命令

#coding:utf8
import time
import sys
import subprocess
from datetime import datetime,date
import subprocess

datestr = str(time.strftime("%Y%m%d",time.localtime(int(time.time()))))

cur_city = ['shanghai','suzhou','nanjing','chongqing','shenyang',
            'dalian','zhengzhou','jinan','xian','haerbin','wuxi','shijiazhuang','chengdu']

cur_dir = 'cd /home/zhuge/project/zhuge-blackwidow/blackwidow/bin; python '
log_dir = '/home/zhuge/project/4.0log/'

for index in range(len(cur_city)):
    log_name = '%s' % (cur_city[index])
    log_file = log_dir + log_name
    command = '%srun.py %s-anjukebd-broker seeds > %s 2>&1' %(cur_dir,cur_city[index],log_file)
    print command
    subprocess.Popen(command,shell=True)
    time.sleep(1)

你可能感兴趣的:(python控制进程在linux系统上运行命令)