Python-从syslog文件中检索信息 [英] Python - retrieving info from a syslog file
本文介绍了Python-从syslog文件中检索信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人要求我使用python编写程序进行作业.
I have been asked to write a program using python for an assignment.
我已获得一个syslog文件,我必须查找有关该文件的信息
I have been given a syslog file and I have to find things out about it
如何找出尝试登录根帐户的次数?
How do I find out how many attempts were made to login to the root account?
任何建议都将受到高度赞赏,因为我是python的新手,而且完全迷路了!
Any advice would be highly appreciated as I am very new to python and completely lost!
推荐答案
类似的东西
#open the file , can be /var/log/messages, /var/log/maillog etc as defined in your system
f=open("mysyslogfile")
count=0
#go through the file
for line in f:
if "<unique pattern for checking root account login>" in line:
count+=1
#close the file
f.close()
print "total count: " ,count
这篇关于Python-从syslog文件中检索信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文