Home / Expert Answers / Computer Science / the-operating-system-logs-many-events-one-file-that-contains-interesting-events-is-var-log-auth-lo-pa930

(Solved): The operating system logs many events. One file that contains interesting events is /var/log/auth.lo ...

The operating system logs many events. One file that contains interesting events is /var/log/auth.log, which shows, in part, unsuccessful logins to your system. Some lines of the file will look like this:

May 26 07:29:20 instance-1 sshd[20327]: Disconnected from port 45177 [preauth]
May 26 07:32:22 instance-1 sshd[20351]: Invalid user nagios from port 49715
May 26 07:32:22 instance-1 sshd[20351]: input_userauth_request: invalid user nagios [preauth]
May 26 07:32:23 instance-1 sshd[20351]: Received disconnect from port 49715:11: Normal Shutdown, Thank you for playing [preauth]

Your task in this exercise is to write a python program to read the lines of data from this file, and print out a sorted list of invalid user names to the screen, one per line, like the partial list shown below.


This isn’t a long program. Depending on how verbose your code is, it should be done in 10-25 lines.

A general outline of this program is to

Open the file

For each line in the file

Find if this line contains an invalid user name

If it does, add the name to a list of names

When all lines have been processed, sort the list

Print each element in the list to the screen on a separate line

Finding the invalid user name is the hardest part of this assignment. Use the fact that the user name is always immediately preceded by either ‘Invalid user’ or 'invalid user'. (Note that there are two lines in the log file for each failed login attempt - you only want to process one of them.

Be sure to comment your code, including a header comment with your name and the date.

Once your program works on your local machine, start your instance from the Cloud Console, then login using the SSH button. From there you can upload your program to your instance. Use the gear icon, then select upload file. The file will end up in your home directory.

Make sure your program still works. Most likely you’ll have to change the path to the file to be exactly ‘/var/log/auth.log’. Your output will be different, since this file is different from the one copied to your local machine. Save your output in a file using output redirection.

Download your output file to your local computer. If you made any changes to your program, download a copy from your instance to your local machine so you can submit it to Canvas.

In a Word document, write a paragraph about what you liked about this assignment, what you disliked or found confusing, and what you do to improve your code if you had another couple of hours to work on it.

We have an Answer from Expert

View Expert Answer

Expert Answer

errors = [] # The list where we will store results. linenum = 0 sub
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe