Question
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
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 61.147.247.146 port 45177 [preauth] May 26 07:32:22 instance-1 sshd[20351]: Invalid user nagios from 159.65.144.233 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 159.65.144.233 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.
aD-min.123 admin admin admin admin admin admin backups web3 zabbix zabbix zabbix zimbra
This isnt 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. The easiest thing to do is use the string function find(), to see if the string Invalid user is in the line. The return value tells you where this string is and then you can fiddle with the line from that point on to get the actual name that is invalid.
- 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 youll 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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started