Corning Community College
CSCS1730 UNIX/Linux Fundamentals
To continue to cultivate your problem solving skills, to practice your shell skills, and to demonstrate your basic scripting skills.
Pipes and command expansions are important concepts and skills that you need to be familiar with as we proceed down the shell scripting rabbit hole.
This project has us playing with various examples that will require regular use of these skills, for the purpose of converting units.
This week's project has 2 points of origin.
First, in the upf1/ sub-directory of the UNIX Public Directory, under a directory by the name of your username, you will find the following file:
Copy this file into your project directory.
The TASK file will contain the particular units to start with and convert to.
Next, you will want to grab the latest version of the unittools suite from the following URL:
You will want to use a tool like wget(1) or curl(1) to non-interactively download it onto your lab46 account, and similarly extract, compile, and install that (check its own README file).
There may be multiple versions of unittools available at the download link. Unless you have specific reason otherwise (for this project, you do not), you want to go for the latest version, which will be reflected by the most recent datestamp encoded in the file's name.
For example, say you have the following:
From visual inspection, you would select the “20170201-09” one, because the date it encodes (Feb 1st, 2017 at 9am) is the most recent in that group. You will find this to be a common practice with many software projects on the internet.
Note, however, that visual inspection alone is not good enough for your steps file. New versions may be released, and your steps file needs to obtain the most recent version available. To facilitate this task, the latest and greatest version of unittools will be listed in a file called LATEST (which you should see near the top of the directory index listing). You can make use of this file to assist you in automating the process of determining and downloading the latest version of the unittools tools.
Once those two steps are complete, you can begin on the tasks listed in your TASK file.
The unittools suite is a collection of command-line tools that perform various unit conversions you may find useful for this project. The tools include:
The tools by default expect input via STDIN, and will output to STDOUT.
These tools have command-line arguments which can alter their default behavior. You may want to review the options and defaults (try running them with the -h argument to see what sort of functionality is available).
In the TASK file, you will be given a set of source quantities/units and destination units you need to construct command-lines for to solve, using the tools provided to you in the unittools suite. You will also want to make use of pipes and command expansions in your solutions.
As an example, take the following (formatted is it would appear in your TASK file):
task: 0 precision: 3 input_value: 35 input_unit: cm output_unit: ft chain_delim: " >> "
With these in mind, we can set about solving this problem, using the tools in combination to arrive at the desired result.
A potential solution would be as follows:
lab46:~/src/SEMESTER/unix/upf1$ echo "35" | cm2in 13.78 in lab46:~/src/SEMESTER/unix/upf1$ echo "13.78" | in2ft 1.15 ft lab46:~/src/SEMESTER/unix/upf1$
But that's not very optimized. We could instead do something better, like:
lab46:~/src/SEMESTER/unix/upf1$ echo "35.000 cm" | cm2in OPTIONS | in2ft OPTIONS 35.000 cm >> 13.780 in >> 1.148 ft lab46:~/src/SEMESTER/unix/upf1$
Note that with precision, you need to instruct the tools to display out to the specified number of decimal places.
We'll want to record our command-lines in the appropriate place. Since this is task #0, we'll want to record it in a file called: task0.cli, which should basically just contain the command-lines you ran, merely placed in a text file.
For final output, we'll want to display the chain of conversions we went through. So, for this above example:
lab46:~/src/SEMESTER/unix/upf1$ ./task0.cli 35.000cm >> 13.780in >> 1.148ft lab46:~/src/SEMESTER/unix/upf1$
Basically, each task#.cli will be its own script. If we were to execute it, the correct result should be produced.
You will once again be creating a steps file that can automate your project (ie it contains a list of non-interactive steps to complete the task).
As in previous projects, upf1steps will contain the steps you took from the point of copying the numbers suite and downloading the unittools suite up until the submit step (hint: just run the task#.cli scripts within the steps script).
There are some additional constraints you need to keep in mind:
For example, a sample output of your upf1steps script should appear like follows (but your # values will of course be different based on your individual TASK file):
lab46:~/src/SEMESTER/unix/upf1$ ./upf1steps Task 0 conversion chain: 35.000cm >> 13.780in >> 1.148ft ... lab46:~/src/SEMESTER/unix/upf1$
By successfully performing this project, you should have a set of task#.cli files (one for each task). You will want to submit these, along with a upf1steps file.
To submit this project to me using the submit tool, run the following command at your lab46 prompt:
$ submit unix upf1 upf1steps task*.cli Submitting unix project "upf1": -> upf1steps(OK) -> task0.cli(OK) -> task1.cli(OK) -> task2.cli(OK) -> task3.cli(OK) ... SUCCESSFULLY SUBMITTED
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
I'll be looking for the following:
78:upf1:final tally of results (78/78) *:upf1:upf1steps has valid list of non-interactive instructions [4/4] *:upf1:upf1steps only modifies files if USER matches [4/4] *:upf1:upf1steps builds the various task#.cli files it runs [4/4] *:upf1:upf1steps obtains the latest unittools release from site [6/6] *:upf1:upf1steps only displays specified STDOUT output [4/4] *:upf1:upf1steps errorlessly creates local project directory [4/4] *:upf1:upf1steps makes clear, effective use of wildcards [4/4] *:upf1:upf1steps defines and uses custom variables [4/4] *:upf1:upf1steps uses command expansions to get information [4/4] *:upf1:upf1steps uses a loop to drive numbers in final output [4/4] *:upf1:upf1steps automates the task when run [4/4] *:upf1:all files are organized, clear, and easy to read [4/4] *:upf1:task#.cli files output using specified precision [4/4] *:upf1:task#.cli files output using specified delimiter [4/4] *:upf1:task#.cli files output only correct value and unit [4/4] *:upf1:task#.cli files output in specified format [4/4] *:upf1:task#.cli files display no STDERR output [4/4] *:upf1:task#.cli files have solution within given constraints [4/4] *:upf1:task#.cli files only contain the solution command-line [4/4]
Additionally: