User Tools

Site Tools


haas:fall2020:unix:projects:upf1

Corning Community College

CSCS1730 UNIX/Linux Fundamentals

Project: UNIX PIPE FUN (upf1)

Errata

  • revision #: <description> (DATESTAMP)

Objective

To continue to cultivate your problem solving skills, to practice your shell skills, and to demonstrate your basic scripting skills.

Background

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.

Get started

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:

  • TASK

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:

  • unittools-20160731-10.tar.gz
  • unittools-20161024-14.tar.gz
  • unittools-20170123-13.tar.gz
  • unittools-20170201-09.tar.gz

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.

unittools suite

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:

  • cm2in - convert centimeters to inches
  • cu2mm - convert cubits to millimeters
  • dm2cm - convert decimeters to centimeters
  • Dm2mi - convert Decameters to miles
  • ft2hm - convert feet to hectometers
  • ft2yd - convert feet to yards
  • hm2dm - convert hectometers to decimeters
  • hm2Dm - convert hectometers to Decameters (if not available, use hm2dcm instead)
  • in2cu - convert inches to cubits
  • in2ft - convert inches to feet
  • km2ft - convert kilometers to feet
  • mi2km - convert miles to kilometers
  • mi2yd - convert miles to yards
  • mm2dm - convert millimeters to decimeters
  • st2mi - convert stadions to miles
  • yd2mi - convert yards to miles
  • yd2st - convert yards to stadions

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).

Process

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/unix/upf1$ echo "35" | cm2in
13.78 in
lab46:~/src/unix/upf1$ echo "13.78" | in2ft
1.15 ft
lab46:~/src/unix/upf1$ 

But that's not very optimized. We could instead do something better, like:

lab46:~/src/unix/upf1$ echo "35.000 cm" | cm2in OPTIONS | in2ft OPTIONS
35.000 cm >> 13.780 in >> 1.148 ft
lab46:~/src/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/unix/upf1$ ./task0.cli
35.000cm >> 13.780in >> 1.148ft
lab46:~/src/unix/upf1$ 

Basically, each task#.cli will be its own script. If we were to execute it, the correct result should be produced.

upf1steps

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).

  • To clarify: YES, I want to see steps creating a project directory, copying and downloading files in question, extracting, compiling, installing, and then of course running each individual task#.cli script.

There are some additional constraints you need to keep in mind:

  • your script should not produce ANY STDERR output
  • your script should ONLY produce STDOUT output in conformance with the below stated requirements. Any other output needs to be silenced.
  • You will want one unified command-line producing the end result, not separate one-step transitions. The idea is to utilize pipes.
    • semi-colons used to separate commands do not constitute one command-line, but several.
  • For each task, you'll want to display things as follows:
    • “Task X conversion chain: CHAIN”
      • where X is the task number (0, 1, 2, etc.)
      • where CHAIN is the conversion chain output matching the TASK file result requested (ie, you must run your task#.cli script to produce this output).
        • note that the task#.cli output appears on the SAME line as the “Task X conversion chain:” text, and there is a single space separating it from the colon.
        • there is NO space between value and unit

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/unix/upf1$ ./upf1steps
Task 0 conversion chain: 35.000cm >> 13.780in >> 1.148ft
...
lab46:~/src/unix/upf1$ 

Submission

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 copies/alters 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 [4/4]
*:upf1:upf1steps only displays specified STDOUT output [4/4]
*:upf1:upf1steps resiliently creates local project directory [4/4]
*:upf1:upf1steps copies public dir data with absolute path [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 [3/3]
*:upf1:task#.cli files output using specified delimiter [3/3]
*: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:

  • Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction
  • Solutions not utilizing indentation to promote scope and clarity will be subject to a 25% overall deduction
haas/fall2020/unix/projects/upf1.txt · Last modified: 2020/03/28 10:37 by 127.0.0.1