DRAFT - Under Construction
Assignment 1 - Usage Report
Weight: 15% of the overall grade
Due Date: Ask your professor for exact date
Late Penalty: 10% per school day, and note that this assignment must be completed satisfactorily in order to pass the course even if you get zero mark for this assignment.
Overview
Most system administrators would like to know the utilization of their systems by their users. On a Linux system, each user's login records are normally stored in the binary file /var/log/wtmp. The login record in this binary file can not be viewed or edited directly using normal Linux text commands like 'less', 'cat', etc. The 'last' command is often used to display the login records stored in this file in a human readable form. Please check the man page of the 'last' command for available options. The following listing is a sample output of the 'last' command with the '-F' flag on:
$ last -F avhuo pts/9 10.43.222.35 Tue Feb 13 16:53:42 2018 - Tue Feb 13 16:57:02 2018 (00:03) clee18 pts/6 10.40.43.94 Tue Feb 13 16:51:47 2018 - Tue Feb 13 16:56:13 2018 (00:04) clee18 pts/6 10.40.43.94 Tue Feb 13 16:50:20 2018 - Tue Feb 13 16:51:27 2018 (00:01) shana pts/2 toroon4512w-lp13 Tue Feb 13 16:47:48 2018 - Tue Feb 13 16:58:31 2018 (00:10) hfang171 pts/4 24.114.50.50 Tue Feb 13 16:31:38 2018 - Tue Feb 13 17:48:39 2018 (01:17) bigia pts/8 10.247.6.126 Tue Feb 13 16:28:43 2018 - Tue Feb 13 17:28:31 2018 (00:59) ckim16 pts/2 10.40.91.236 Tue Feb 13 16:22:36 2018 - Tue Feb 13 16:45:10 2018 (00:22) ddchan pts/2 10.43.115.162 Tue Feb 13 16:19:29 2018 - Tue Feb 13 16:22:00 2018 (00:02) tsliu2 pts/4 10.40.105.130 Tue Feb 13 16:17:21 2018 - Tue Feb 13 16:30:10 2018 (00:12) shana pts/13 10.40.91.247 Tue Feb 13 16:07:52 2018 - Tue Feb 13 16:45:52 2018 (00:38) tchiu2 pts/11 10.40.105.130 Tue Feb 13 16:07:43 2018 - Tue Feb 13 16:17:12 2018 (00:09) ...
In this assignment, your task is to create a python program to produce daily, weekly, and monthly usage reports by user or by remote host based on the information obtained from the 'last' command or given files which contain similar information as the 'last' command.
Instructions
Program Name and valid command line arguments
Name your Python3 program as usage_report.py
. The program should accept zero or more "file name" as its command line parameters. for examples:
-
python3 usage_report.py
, or -
python3 usage_report.py filename
, or -
python3 usage_report.py filename1 filename2
etc ... - any number of file names from 1 to as many as the command-line supports.
If there is no command line argument, your python program should get the login records from the 'last' command with the appropriate flags.
If there is one file name provided at the command line, read the login records from the contents of the given file. The format of each line in the file should be the same as the output of 'last -Fiw'.
If there is more than one file name provided, merges all the files together with the first one at the top and the last one at the bottom. Read and process the file contents in that order in your program.
Header
All your Python codes for this program must be placed in a single source file. Please include the following declaration by you as comment in your Python source code file (replace "Student Name" with your own name):
OPS435 Assignment 1 - Winter 2018
Program: usage_report.py
Author: "Student Name"
The python code in this file (usage_report.py) is original work written by
"Student Name". No code in this file is copied from any other source
including any person, textbook, or on-line resource. I have not shared
this python program with anyone or anything except for submission for grading.
I understand that the Academic Honesty Policy will be enforced and violators
will be reported and appropriate action will be taken.
Main Menu
When your Python program is running, it should present the user with the following menu:
Reading login records... Done.
Usage Report - Main Menu
========================
d) Daily Usage Report
w) Weekly Usage Report
m) Monthly Usage Report
q) Quit
Display an appropriate sub-menu when option d, w, or m is selected.
When option q is selected, you program should terminate.
Redisplay the same menu if the user entered any other letters.
Daily Usage Menu
- If the Daily Usage Report option is selected from the Main Menu, the following sub-menu should be presented on the screen:
Daily Usage Report Menu
=======================
u) By User
h) By Remote Host
r) Return to Main Menu
When option u is selected, the sub-menu for Daily Usage Report by User should be displayed.
When option h is selected, the sub-menu for Daily Usage Report by Remote Host should be displayed.
When option r is selected, the main menu should be displayed.
Redisplay the same menu if the user entered any other letters.
Daily Usage Report by User
Daily Usage Report - by User
============================
0) All users
1) user1
2) user2
3) user3
...
9) user9
r) Return to Daily Usage Report Menu
Note: If there are fewer than 9 users, display only the actual number of users on the menu.
When option r is selected, the previous Daily Usage Report menu should be displayed.
When one of 0-9 is selected, the Daily Usage Report for the selected user(s) should be generated.
Redisplay the same menu if the user entered any other digits/letters.
The following is a sample Daily Usage Report for user1 on host.cty.senecacollege.ca:
Daily Usage Report for user1 on host.cty.senecacollege.ca ========================================================= Date Usage in Minutes 2018-02-14 60 2018-02-07 45 2018-02-01 5 Total 110
Daily Usage Report by Remote Host
Daily Usage Report - by Remote Host
===================================
0) All Remote Host
1) 10.94.10.25
2) 10.94.10.120
3) 172.16.99.1
...
9) 192.168.45.3
r) Return to Daily Usage Report Menu
Note: If there are fewer than 9 remote hosts, display only the actual number of remote host on the menu.
When option r is selected, the previous Daily Usage Report menu should be displayed.
When one of 0-9 is selected, the Daily Usage Report for the selected Remote Host(s) should be generated.
Redisplay the same menu if the user entered any other digits/letters.
The following is a sample Daily Usage Report from Remote Host 10.94.10.25 on host.cty.senecacollege.ca:
Daily Usage Report from 10.94.10.25 on host.cty.senecacollege.ca ================================================================ Date Usage in Minutes 2018-02-14 30 2018-02-07 41 2018-02-01 9 Total 80
Weekly Usage Menu
- If the Weekly Usage Report option is selected from the Main Menu, the following sub-menu should be presented on the screen:
Weekly Usage Report Menu
========================
u) By User
h) By Remote Host
r) Return to Main Menu
When option u is selected, the sub-menu for Weekly Usage Report by User should be displayed.
When option h is selected, the sub-menu for Weekly Usage Report by Remote Host should be displayed.
When option r is selected, the main menu should be displayed.
Weekly Usage Report by User
Weekly Usage Report - by User
=============================
0) All Users
1) User1
2) User2
3) User3
...
9) User9
r) Return to Weekly Usage Report Menu
Note: If there are fewer than 9 users, display only the actual number of user on the menu.
When option r is selected, the previous Weekly Usage Report menu should be displayed.
When one of 0-9 is selected, the Weekly Usage Report for the selected user(s) should be generated from week 1 to week 52, skips the week where the weekly usage is zero.
Redisplay the same menu if the user entered any other digits/letters.
The following is a sample Weekly Usage Report for user1 on host.cty.senecacollege.ca:
Weekly Usage Report for user1 on host.cty.senecacollege.ca ========================================================= Week # Usage in Minutes 1 160 2 45 3 5 4 20 Total 220
Weekly Usage Report by Remote Host
Weekly Usage Report - by Remote Host
===================================
0) All Remote Hosts
1) 10.94.10.25
2) 10.94.10.120
3) 172.16.99.1
...
9) 192.168.45.3
r) Return to Weekly Usage Report Menu
Note: If there are fewer than 9 remote hosts, display only the actual number of remote host on the menu.
When option r is selected, the previous Weekly Usage Report menu should be displayed.
When one of 0-9 is selected, the Weekly Usage Report for the selected Remote Host(s) should be generated from week 1 to week 52, skip the week where the weekly usage is zero.
Redisplay the same menu if the user entered any other digits/letters.
The following is a sample Weekly Usage Report from the remote host 10.94.10.25 on host.cty.senecacollege.ca:
Daily Usage Report from 10.94.10.25 on host.cty.senecacollege.ca ================================================================ Week # Usage in Minutes 1 30 3 41 5 9 6 11 Total 91
Monthly Usage Menu
- If the Monthly Usage Report option is selected from the Main Menu, the following sub-menu should be presented on the screen:
Monthly Usage Report Menu
=========================
u) By User
h) By Remote Host
r) Return to Main Menu
When option u is selected, the sub-menu for Monthly Usage Report by User should be displayed.
When option h is selected, the sub-menu for Monthly Usage Report by Remote Host should be displayed.
When option r is selected, the main menu should be displayed.
Monthly Usage Report by User
Monthly Usage Report - by User
==============================
0) All Users
1) User1
2) User2
3) User3
...
9) User 9
r) Return to Monthly Usage Report Menu
Note: If there are fewer than 9 users, display only the actual number of user on the menu.
When option r is selected, the previous Monthly Usage Report menu should be displayed.
When one of 0-9 is selected, the Monthly Usage Report for the selected user(s) should be generated for Jan to Dec. Skips the month where the Monthly Usage is zero.
Redisplay the same menu if the user entered any other digits/letters.
The following is a sample Monthly Usage Report for user1 on host.cty.senecacollege.ca:
Monthly Usage Report for user1 on host.cty.senecacollege.ca =========================================================== Month Usage in Minutes January 160 February 45 Total 205
Monthly Usage Report by Remote Host
Monthly Usage Report - by Remote Host
=====================================
0) All Remote Hosts
1) 10.94.10.25
2) 10.94.10.120
3) 172.16.99.1
...
9) 192.168.45.3
r) Return to Monthly Usage Report Menu
Note: If there are fewer than 9 remote hosts, display only the actual number of remote host on the menu.
When option r is selected, the previous Monthly Usage Report menu should be displayed.
When one of 0-9 is selected, the Monthly Usage Report for the selected Remote Host(s) should be generated for Jan to Dec. Skips that month where the Monthly Usage is zero.
Redisplay the same menu if the user entered any other digits/letters.
The following is a sample Monthly Usage Report for 10.94.10.25 on host.cty.senecacollege.ca:
Monthly Usage Report from 10.94.10.25 on host.cty.senecacollege.ca ================================================================ Week # Usage in Minutes January 30 February 41 Total 71
Sample login records file
- Will be provide on Feb 22, 2018
Rubric
Task | Maximum mark | Actual mark |
---|---|---|
Program Authorship Declaration | 1 | |
Main Menu | 2 | |
Daily Usage Menu | 1 | |
Daily Usage Report by User Menu | 1 | |
Daily Usage Report by Remote Host Menu | 1 | |
Weekly Usage Menu | 1 | |
Weekly Usage Report by User Menu | 1 | |
Weekly Usage Report by Remote Host Menu | 1 | |
Monthly Usage Menu | 1 | |
Monthly Usage Report by User Menu | 1 | |
Monthly Usage Report by Remote Host Menu | 1 | |
Get Login Records from 'last' | 3 | |
Get Login Records from files | 3 | |
Generate Daily Usage Report | 2 | |
Generate Weekly Usage Report | 2 | |
Generate Monthly Usage Report | 2 | |
Total | 24 |
Submission
After fully testing your program, submit the .py file on Blackboard