#!/usr/bin/python
import os,string
#import Base
def getlist(path,service):
os.chdir(path)
s=os.listdir(path)
for i in range(0,len(s)):
if s
==service:
os.chdir(service)
h = open("list.txt")
infile = h.readlines() or []
h.close()
if infile:
infile = [line.rstrip('\r\n') for line in infile]
return infile
x=getlist("/root/python/service/","oss")
print x
def execmysql(mysql_databaseaddress,mysql_databaselogin,mysql_databasepasswd,mysql_databasename,mysql_sqlfilepath,mysql_sqlfilename):
result=os.system('mysql -h%s -u%s -p%s %s < %s/%s ' %(mysql_databaseaddress,mysql_databaselogin,mysql_databasepasswd,mysql_databasename,mysql_sqlfilepath,mysql_sqlfilename))
if result==0:
print ("ok,execmysqlfile %s/%s succeed!" %(mysql_sqlfilepath,mysql_sqlfilename))
else:
print ("execmysqlfile %s/%s failed!" %(mysql_sqlfilepath, mysql_sqlfilename))
execmysql("10.10.30.187","sstv","sstv@2009","tvdoss","/root/python/service/oss/init",x)
為什麼我執行的時候她出現這樣的錯誤:
[root@localhost python]# python ttt.py
['a.sql', 'b.sql', 'c.sql']
sh: /root/python/service/oss/init/[a.sql,: No such file or directory
[2009-07-28 14:35:52,410](ERROR)intall : execmysqlfile /root/python/service/oss/init/['a.sql', 'b.sql', 'c.sql'] failed!
為什麼會帶了個“[”,execmysql這個函數是沒問題的。getlist函數怎樣實現讀取指定文件list.txt裡的行,並執行每行。
那為高手能幫我解決下這個問題!