I need to read the linux /var/log/auth.log file and print the user of unsuccessful logins to the system. Some lines of the file will look like this:
May 26 07:29:20 instance-1 sshd: Disconnected from 22.214.171.124 port 45177 [preauth]
May 26 07:32:22 instance-1 sshd: Invalid user nagios from 126.96.36.199 port 49715
May 26 07:32:22 instance-1 sshd: input_userauth_request: invalid user nagios [preauth]
May 26 07:32:23 instance-1 sshd: Received disconnect from 188.8.131.52 port 49715:11: Normal
May 26 07:32:22 instance-1 sshd: Invalid user admin from 184.108.40.206 port 49715
I need to read the lines of data from this file, and print out a sorted list to a file of invalid user names, one per line, like the list shown below.
I have got this far but I need it to print out the word AFTER the string.
errors =  # The list where we will store results.
linenum = 0
substr = "Invalid user" # Substring to search for.
with open ('auth.log', 'rt') as myfile:
for line in myfile:
linenum += 1
if line.find(substr) != -1:
for line in errors: