# -*- coding:utf-8 -*-
#working for fs2log
import sys,os
import time
#查找路径
def file_dir():
path = sys.path[0]
if os.path.isdir(path):
return path
elif os.path.isfile(path):
return os.path.dirname(path)
#输出结果
def output(log,path,month):
txtlog = log
recordfile = os.path.join(path+'/'+month)
try:
fp = open(recordfile , "a+")
print >>fp , txtlog
fp.close()
except:
pass
运行shell
def runshell(path,command,day):
cmd = command
a = os.popen(cmd.replace('data',day).replace('path',path)).read()
return a
读取shell
def readconfig(path,day,month):
thecmd = open(path+'/command','rb')
printout = ''
printout = day
try:
for line in thecmd.xreadlines():
printout=printout+' '+runshell(path,line,day)[:-1]
print printout
thecmd.close()
except:
pass
output(printout,path,month)
#参数时间,
def main():
if len(sys.argv)>1:
LogDate=sys.argv[1]
LogMonth=sys.argv[1][0:6]
readconfig(file_dir(),LogDate,LogMonth)
else:
LogDate=time.strftime('%Y%m%d',time.localtime(time.time()-86400))
LogMonth=LogDate[0:6]
readconfig(file_dir(),LogDate,LogMonth)
if __name__ == "__main__":
main()
python linux shell
最新推荐文章于 2024-02-06 10:13:48 发布