我正在尝试创建一个脚本,它将从许多组件中拖尾日志并写入单个文件。当我摄取由许多组件处理的视频资产时,我需要启动此脚本。首先,我试图只尾部1个组件,但似乎不起作用。有人可以帮助我吗?
from __future__ import with_statement
from fabric.api import *
import re, ConfigParser, paramiko, xlwt, collections, os
import logging
from logging.config import fileConfig
logger = None
def connect():
global config, logger, status, file_size
config = ConfigParser.RawConfigParser()
config.read('config.cfg')
for section in sorted(config.sections(), key=str.lower):
env.user = config.get(section, 'server.user_name')
env.password = config.get(section, 'server.password')
host = config.get(section, 'server.ip')
print "Trying to connect to {} server.....".format(section)
with settings(hide('warnings', 'running', 'stdout', 'stderr'),warn_only=True, host_string=host):
try:
files = run('tail -F /var/log/abc')
with open("E2E_tmp"+".txt", "w") as fo:
fo.write(files)
except Exception as e:
print e
print 'Could not connect to {} server\n'.format(section)
if __name__ == "__main__":
connect()
Config就像这样
[Astro]
server.user_name = root
server.password = staines
server.ip = 10.209.17.113
脚本将显示
Trying to connect to Astro server.....
如果我使用'ls'命令,我可以看到文本文件中的列表,而不是tail命令。请帮助我如何将许多文件中的尾部直接拖到单个文件中,或者有更好的方法来执行此操作。
注意:我正在从Windows PC运行脚本。