upload egg的执行方法是 upload -m 参数1 -v /home/log/1.log -c /home/config/1.config -e 0 -p 11111
因为Home的log文件夹下有每一天的log文件需要上传,我现在需要自己写一个python或者shell脚本去调用这个已经安装好的upload模块,去上传这些log文件。
要求:
遍历log 文件夹下的文件,Log文件夹目录:
Log--
----config
----1.config
----2.config
----vlog----
-----2015-01-01
1-1-1-1.log
1-2-1-1.log
....
-----2015-01-02
1-1-1-1.log
1-2-1-1.log
....
拿到对应的config文件
遍历这些文件,然后自动不停的上传,上传的py文件已经有了。直到log目录下的文件上传完毕。
import os
path = "~/log"
def enumeratepaths(path=path):
configs = []
for dirpath, dirnames, filenames in os.walk(path):
for file in filenames:
if "config" in file:
fullpath = os.path.join(dirpath, file)
configs.append(fullpath)
# 看你的`upload`的参数还可能需要`log`文件
# basename = os.path.basename(fullpath)
# log_path = os.path.join(dirpath, basename.split('.')[0] + '.log'
return configs
拿到路径之后可以用os.system或者subprocess来调用upload.
这里的code仅作参考. 具体可以看看OReily 的 Python for Unix and Linux System Administration (2008) 的第六章 Working with Paths, Directories, and Files
玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/wenda/wd18790.html
相关文章 Recommend