Question
The purpose of this exercise is to write a Python program to process a log file and print some summary results. The philosophy of programs
The purpose of this exercise is to write a Python program to process a log file and print some summary results. The philosophy of programs like this is to write all output to the screen. After the program is working, youll use output redirection to save the results to a file.
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
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, and 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.
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