I have developed a script to calculate how many times some one has tried to login using a root account. I am using the resources from a separate document which contains all the login attempts.
myfile = open ('/home/Parker4001/Desktop/loginAttempts','r')
counter_root = 0
for line in myfile.readline():
list_of_line1 = line.split(' ')
if 'Failed password for root' in line:
counter_root = counter_root +1
print 'Attempt to login with root = ' , counter_root
This is the code i have so far which gives me the following output
Attempt to login with root = 0
Attempt to login with root = 0
Attempt to login with root = 0
Attempt to login with root = 0
Attempt to login with root = 0
Attempt to login with root = 0
The problem i am having is that i want a grand total rather than multiple lines + the counter_root doesn’t seem to be adding up the attempts to log in any help would be much appreciated.
Also change
to
since
myfile.readline()gives you just the first line of the file,and iterates over the bytes in the line. In contrast,
foriterates over the lines of the file.line in myfile