Keep a log in the file lab3.txt of what you do in the lab so that you can reproduce the results later. This should not merely be a transcript of what you typed: it should be more like a true lab notebook, in which you briefly note down what you did and what happened.
You're helping to build an application containing a shell script that invokes the df command to check whether there is enough free disk space. Your application is running atop the Maroon Chapeau 7 distribution. You've been running into the problem that df occassionally fails with a diagnostic that looks like this:
df: `/var/named/chroot/proc': Permission denied
You've been asked to look into the problem and fix it.
You discover that the problem is that in some cases a user won't have any access to a mounted file system, and so df will report that the file system is inaccessible as shown above. The shell command df --version tells you which version of the GNU Core Utilities (coreutils) package that Maroon Chapeau 7 is using; this turns out to be coreutils version 5.92.
You nose around on the net, and discover that the bug has been fixed in more recent versions of coreutils so one option is to upgrade to a newer coreutils; but your boss suggests that you just patch the old version instead. So you look around some more, and find that someone with the pseudonym of n0dalus reported a similar bug on 2005-10-09 and posted a small, purported fix for it on 2005-10-12.
Try n0dalus's fix, as follows:
Consider the Python script randline.py.
What happens when this script is invoked on an empty file like /dev/null, and why?
Currently randline.py outputs lines with replacement; for example, it's possible that it will output the first input line two or more times. Modify randline.py so that it accepts a new option -p which causes it to output lines without replacement. That is, when the user specifies the option -p, the modified program will never output any input line more than once. If the user does not specify -p the program should behave as before (except its usage message should mention -p). With -p it is an error if the input file contains fewer than the number of lines requested, just as it is already an error without -p to invoke randline.py on an empty file and ask it for one or more lines of output. You need not worry about the exact diagnostic you generate for this new error, so long as you generate some diagnostic.
Your modified version of randline.py should use only the modules that randline.py uses (it should not import any other modules), and it should not use the sample function, since we want your solution to be portable to older Python implementations.
Submit the following files.
All files should be ASCII text files, with no carriage returns, and with no more than 80 columns per line. The shell command:
expand lab3.txt hw3.txt randline.py | awk '/\r/ || 80 < length'
should output nothing.