Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

One of the shortcomings of the last command within vim is that there is no summation or reporting facility to tell someone using the command

One of the shortcomings of the last command within vim is that there is no summation or reporting facility to tell someone using the command an overall summary of how long someone has used the system over the course of a month or how many times the person connected. For a company that might charge for hourly usage of their system, it would be helpful if there was a utility that would generate these kinds of basic statistics as well as provide a listing of all logins for a specific account.

The objective is to write a Perl script that also use use Modern::Perl; and regular expressions to display summary information about a single user's account on the system. Here are the specifications for your program; make sure you read and understand all requirements before proceeding:

1. Your program must take one command-line argument, which will be the name of the account to summarize. If no command-line argument is given, display a usage statement and exit the program. You can assume that the account exists; no valiation of this fact is necessary.

2. Your program will then process the output from last and display a summary of that accounts activity including the following information: account name, how many logins were executed, and the time in HH:MM format (not DD+HH:MM ).

You must display each login entry, prefaced by a login # (sequential numbers starting at 1). See the final page for a complete example of the output. Make sure your final output follows this formatting, where the time should be in the format HH:MM , where HH and MM (hours and minutes) should both be two digits in length, including leading 0s if necessary. The user's full account name, logins and time should each be displayed on separate lines in that order:

FULL_ACCOUNT_NAME

NUMBER_OF_LOGINS

TOTAL_TIME_IN_HH:MM

You may assume that the account provided on the command line is valid and that the account exists. Whether or not that individual has any logins is a condition that should be handled appropriately. You will need to make sure that you handle accounts that have the D+HH:MM format listed for their logins. To get a listing of accounts that match this, use the Unix grep command like this:

[Loki] :~:> last | grep +

This will give you a listing of accounts that have entries in the D+HH:MM format that you can then test in your program. Make sure to handle if the command-line argument that is provided is longer than 8 characters. last only records the first 8 characters of a user's account, so you'll need to handle if someone provides bartsimpson for the command-line argument and locate only bartsimp entries from the output of last .

Make sure to stop the program if no command-line argument is given or too many command line arguments are provided. Provide a usage statement if no command-line argument is given, and make sure to use $0 in your usage statement to produce the correct output. Do not process partial command-line arguments, such as if the program were run with ./lastsummary.pl art , it shouldn't bring up a summary of all logins that contain the text art . The only listings that should match would be a username of art , so no listings for bartsimp , for instance, should show up. Do not convert the time summary to days, hours and minutes. Make sure your total time output is only in total hours and minutes. Do not use the last account format of last or last account | grep account to get just information for a particular user. Your program will not be graded if you use either of these methods to obtain your user list. One of the goals of this program is to practice matching with regexes. Your output capture statement should look like this:

my @lastoutput = `last`;

I have provided a sample run below so you can see the correct output

image text in transcribed

username@Loki $ lastsummary mtucker Here is a listing of the logins for mtucker: 1. mtucker pts/2 2. mtucker pts/e . mtucker pts/1 ip68-13-82-64.om Fri Sep 3 07:54 - 20:02 (2+12:07) ip68-13-82-64.om Thu Sep 2 19:45- 20:15 (00:30) 37.48.288.181 Thu Sep 2 13:39 16:50 (03:11) Here is a summary of the time spent on the system for mtucker: mtucker 63:48 username@Loki $ lastsummary mtucker Here is a listing of the logins for mtucker: 1. mtucker pts/2 2. mtucker pts/e . mtucker pts/1 ip68-13-82-64.om Fri Sep 3 07:54 - 20:02 (2+12:07) ip68-13-82-64.om Thu Sep 2 19:45- 20:15 (00:30) 37.48.288.181 Thu Sep 2 13:39 16:50 (03:11) Here is a summary of the time spent on the system for mtucker: mtucker 63:48

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

11. Are your speaking notes helpful and effective?

Answered: 1 week ago

Question

The Goals of Informative Speaking Topics for Informative

Answered: 1 week ago