OPS435 Assignment 1 A
DRAFT - Under Construction
Assignment 1 - Users' Usage Report
Weight: 20% 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, the users' login records are normally stored in the binary file /var/log/wtmp. The login records in this binary file can not be viewed or edited directly using normal Linux 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. The following listing is a sample output of running the 'last' command:
$ 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 with well designed functions to produce daily, weekly, and monthly usage report by user or remote host based on the information obtained from 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 command line parameters:
-
filename
, or -
filename1 filename2
etc ... - any number of filenames 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 filename provided at the command line, gets the login records from the contents of the given file. The format of the lines in the file should be the same as the output of 'last -F'.
If there is more than one filename 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 based on the given command line arguments:
Reading login records... Done.
Usage Report - Main Menu
========================
d) Daily Usage Report
w) Weekly Usage Report
m) Monthly Usage Report
q) Quit
Option d, w, and m when selected will display a new sub-menu.
When option q is selected, you program should terminate.
Daily Usage Menu
- If the command line option
--user
or-u
is set, and the Daily Usage Report option is selected from the Main Menu, the following sub-menu should be presented on the screen:
Daily Usage Report - by User
============================
1) user1
2) user2
3) user3
...
r) Return to Main Menu
Daily Usage Report for the user selected should be displayed on the screen when selected.
When option r is selected, your program should return and display the main menu.
- If the command line option
--user
or-u
is not set, and the Daily Usage Report option is selected from the Main Menu, the following sub-menu should be presented on the screen:
Daily Usage Report - by Remote Host
===================================
1) remote host 1
2) remote host 2
3) remote host 3
...
r) Return to Main Menu
Daily Usage Report via the remote host selected should be displayed on the screen when selected.
When option r is selected, your program should return and display the main menu.
Weekly Usage Menu
Monthly Usage Menu
Sample login records file
Submission
After fully testing your program, submit the .py file on Blackboard