Question
This is for Ruby Programming I'm having a hard time getting this to work for my last project that's extra credit. 1. The report should
This is for Ruby Programming I'm having a hard time getting this to work for my last project that's extra credit.
1. The report should include the following information for each user: Information Description Linux user id The user id that is used to login (ie doej123) Full Name The full name of the user (ie John Doe). Login Date/Time The most recent login date and time Total Number of Logins (self-explanatory) List of IP Address or FQDNs Each time the user has logged in, their IPAddress or FQDN (Fully Qualified Doman Name) is recorded.
In order to obtain the full name, you will need to use the "getent" command. Historically, the full name field was known as the "GECOS field" and was used for the full name, office number, etc. You will invoke the "getent" command after obtaining the Linux user id. The following is an example of how to invoke the "getent" command Notice that the full name is fifth of the : separated fields in the output. If there is no record returned for a user, leave it as a blank (nil). 2. Each user's information shall be on a single line. Meaning, if the report lists 5 users, then there will be 5 lines of information. 3. The report's output should be generated in CSV format such that if we redirect the output of the Ruby script using > in the shell or supply an output file name, the CSV file will be saved and can be transferred to a PC running Microsoft Excel and saved as a spreadsheet. 4. The Ruby program will have the following Command-line options and must be managed using the optparse library: ? -i : pass-through to the "last" command, telling it to convert FQDNs to IP addresses ? -f : pass-through to the "last" command, telling to it read from a specific wtmp file ? -o : send the report output to the named file ? -h : show the command usage summary
Program Flow 1. Create a user hash that will store the user information. This will be your information store.
2. (15 points) Parse the Command-line options.
3. (10 points) Invoke the "last" command passing any command-line arguments.
4. Loop through each line of data that was produced by the "last" command.
5. With each iteration do the following: a. Split the line of data to obtain key information. This can be done by using the .split() method b. Check to see if the Linux user id has been processed before. If not, do the following: i. (10 points) Using the Linux user id, invoke the "getent" command to get the Full Name. Again, split the information using the necessary token. ii. (10 points) Capture the Linux user id, full name, and the login date/time iii. Store the user information to your information store. c. Since every line in the "last" command represents a user login, using your information store, lookup by the Linux user id. Note: This will be done every time, so for part 5.b you should set some default values. Do the following: i. (10 points) Increment the Total Login Count ii. (10 points) Append the IP Address / FQDN to the user's list.
6. Once completed, iterate through the list of users. Do the following: a. (10 points) Output report in CSV format. Output will either be to the console, or if the o option is present to the output file.
Additional Information 1. (10 points) Your program should run as expected, so Basic Syntax and Runtime Behavior will be enforced.
2. (5 points)The final two lines of the "last" command are a blank line and a summary line stating when the file was started (generally the 1st of the month): wtmp begins Sun Nov 1 10:38:55 2015 When parsing the output from the "last" command, you will need to skip over the last two lines. The following regular expression will allow you to do so. next if line =~ /^wtmp*/ || line =~ /^$/
3. (10 points) General programming style, such as comments, indentation and variable names, will be applied.
Bonus Points 1. (5 points) Rather than discard the summary line, extract the date and add a header line to the report that uses the "wtmp begins" date and the date on which the script was run to generate a header line such as "Login Activity report for the period 4/1/2016 through 4/25/2016" where the actual dates are derived as described above.
2. (10 points) Create a User class to hold all of the user information. Each time a new Linux user id is encountered, create a User object and store it in your information store. You will find it to be much easier.
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