Commit 26c31feb authored by ibuler's avatar ibuler

修改记录日志bug

parent d8e4efe7
...@@ -110,6 +110,7 @@ def connect(host, port, user, password): ...@@ -110,6 +110,7 @@ def connect(host, port, user, password):
"""Use pexpect module to connect other server.""" """Use pexpect module to connect other server."""
log_date_dir = '%s/%s' % (log_dir, time.strftime('%Y%m%d')) log_date_dir = '%s/%s' % (log_dir, time.strftime('%Y%m%d'))
if not os.path.isdir(log_date_dir): if not os.path.isdir(log_date_dir):
os.mkdir(log_date_dir)
os.mkdir(log_date_dir, 0777) os.mkdir(log_date_dir, 0777)
structtime_start = time.localtime() structtime_start = time.localtime()
datetime_start = time.strftime('%Y%m%d%H%M%S', structtime_start) datetime_start = time.strftime('%Y%m%d%H%M%S', structtime_start)
...@@ -250,10 +251,11 @@ def exec_cmd_servers(username): ...@@ -250,10 +251,11 @@ def exec_cmd_servers(username):
break break
exec_log_dir = os.path.join(log_dir, 'exec_cmds') exec_log_dir = os.path.join(log_dir, 'exec_cmds')
if not os.path.isdir(exec_log_dir): if not os.path.isdir(exec_log_dir):
os.mkdir(exec_log_dir, 0777) os.mkdir(exec_log_dir)
os.chmod(exec_log_dir, 0777)
filename = "%s/%s.log" % (exec_log_dir, time.strftime('%Y%m%d')) filename = "%s/%s.log" % (exec_log_dir, time.strftime('%Y%m%d'))
f = open(filename, 'a') f = open(filename, 'a')
f.write("DateTime: %s User: %s Host: %s Cmds: %s" % f.write("DateTime: %s User: %s Host: %s Cmds: %s\n" %
(time.strftime('%Y/%m/%d %H:%M:%S'), username, hosts, cmd)) (time.strftime('%Y/%m/%d %H:%M:%S'), username, hosts, cmd))
for host in hosts: for host in hosts:
remote_exec_cmd(host, username, cmd) remote_exec_cmd(host, username, cmd)
......
...@@ -19,6 +19,7 @@ def log_hanler(logid): ...@@ -19,6 +19,7 @@ def log_hanler(logid):
if log: if log:
log = log[0] log = log[0]
filename = log.logfile filename = log.logfile
if os.path.isfile(filename):
ret1 = os.system('cat %s | grep "DateTime" > %s.his' % (filename, filename)) ret1 = os.system('cat %s | grep "DateTime" > %s.his' % (filename, filename))
ret2 = os.system('cat %s | grep "\[.*@.*\][\$\#]" >> %s.his' % (filename, filename)) ret2 = os.system('cat %s | grep "\[.*@.*\][\$\#]" >> %s.his' % (filename, filename))
ret3 = os.system('cat %s | grep "EndTime" >> %s.his' % (filename, filename)) ret3 = os.system('cat %s | grep "EndTime" >> %s.his' % (filename, filename))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment