Changes

Jump to: navigation, search

OPS435 Python Assignment 2

510 bytes added, 15:38, 11 November 2018
no edit summary
==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 records 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:
<pre>
$ last -F
</pre>
In this assignment, your task duty is to create a python program to produce # work out an algorithm for producing 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. # Once you believe you have a workable algorithm, you should then identify the different tasks in your algorithm and any repeated sub-tasks,# implement your solution using a python script with the proper use of functions, and finally# review your working python code to see whether you can improve the interface of each function and facilitate better core re-use (this process is called refactoring).
== Resource Modules you can use in your script for useful modules this assignment ==* the <b>os, sys</b> modules
* the <b>argparse</b> module
** [https://docs.python.org/3/howto/argparse.html Argparse Tutorial] - should read this first.
** [https://www.tutorialspoint.com/python3/python_date_time.htm Time module Tutorial]
** [https://docs.python.org/3/library/time.html Time module API reference page]
== Instructions ==
=== Program Name and valid command line arguments ===
Name your Python3 program script as <code>urur_[student_id].py</code>. The program should Your script must accept one or more "file name" as its command line parameters and other optional parameters as shown below. Your ur.py python script should produce the following usage text when run with the --help option:
<pre>
[rchan@centos7 a1]$ python3 ./ur.py -h
usage: urur_rchan.py [-h] [-l {user,host}] [-r RHOST] [-t {daily,weekly,monthly}]
[-u USER] [-v]
F [F ...]
If one of the file name given is "last", 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 /logout 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'. Filter out incomplete login/logout record (check for the number of fields in each record).
If there is more than one file name provided, merges merge 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 ===
</pre>
== Program Suggested Script Development and Testing ==You should create The following python functions (to handle be created) are useful in handling the following sub-tasks:
* gets login records from the output of "last" command and filters out unwanted records
* reads login records from files and filters out unwanted records
* generate daily usage reports by user and/or by remote host* generate weekly usage reports by user and/or by remote host* generate monthly usage reports by user and/or by remote hostTo help you with this assignment, [[OPS435 A1 Usage Report Template|here is a template]] you can use as a starting point in developing your own Python Usage Report programscript.
Once you have finished coding a function, you should start a Python3 interactive shell, import your functions and manually call the function you want to testunder interactive mode.
Once you have all the individual function tested and that each is working properly, perform the final test with test data provided by your professor and verify that your program script produces the correct results before submitting your python program on Blackboard.
== Sample login records file and sample run ==
1,760
edits

Navigation menu