我需要用重新编译并拆分以接收cmd并打印出ip地址(最后一列)和日期和时间,并将其转换为epoch时间。
我用的只是重新编译但有人告诉我要使用split命令来简化。。只是想找些指导?
这就是输出的样子host:~ # last -a -F | egrep -v "boot|wtmp|tty"
root pts/2 Fri Jun 19 10:32:13 2015 still logged in xx.x.xx.xx
root pts/0 Fri Jun 19 08:22:29 2015 still logged in xx.xx.xx.xx
root pts/5 Thu Jun 18 10:09:30 2015 - Thu Jun 18 17:20:52 2015 (07:11) xx.xx.xx.xx
root pts/4 Thu Jun 18 09:53:33 2015 - Thu Jun 18 17:04:53 2015 (07:11) xx.xx.xx.xx
last_re = re.compile(r'(?P\S+)\s+(?P\/.+)\s(?P\S+)\s+(?P)\s+(?P\d+)\s+(?P(\d\:\d)\s+(?P(\s|-)\s+(?P(\d\:\d)\s+(?P)\s+(?P(\(\d\:\d\))\s+(?P(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$)')
cmd = 'last -a -F | egrep -v "boot|wtmp|tty"'
try:
status, output = commands.getstatusoutput(cmd)
print last_re;
if not status:
output_lines = output.split('\n')
m = last_re.search(output_lines[1])
if m:
print "" % (m.group('day'), m.group('month'), m.group('stime'), m.group('ipaddress'))