Corning Community College CSCS1730 UNIX/Linux Fundamentals ======Project: UNIX PIPE FUN (upf0)====== =====Errata===== * any bugfixes or project updates will be posted here =====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 throwing numbers and math operations together to produce desired results (and in desired composition). =====Get started===== This week's project has 2 points of origin. First, in the **upf0/** sub-directory of the UNIX Public Directory, you will find the following archive: * **numbers.tgz** Then, under a directory by the name of your username within that same directory, there will be another file: * **TASK** Copy both of these files into your project directory. The **TASK** file will contain the particular command-line equations you have to perform, along with their stated constraints. The **numbers.tgz** file needs to be extracted, compiled, and installed; there is a README file located within the archive with further instructions on how to do this. Next, you will want to grab the latest version of the **pipemath** suite from the following URL: * https://lab46.g7n.org/~wedge/projects/pipemath/ 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 **pipemath** 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: * pipemath-20160731-10.tar.gz * pipemath-20161024-14.tar.gz * pipemath-20170123-13.tar.gz * pipemath-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 pipemath 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 pipemath tools. Once those two steps are complete, you can begin on the tasks listed in your **TASK** file. ====numbers suite==== The numbers suite is basically a collection of command-line tools whose purpose is to display a single digit number, in accordance with the tool's name. For example, when you run the **zero** tool, a **0** is displayed to STDOUT. For **one**, a **1** is displayed to STDOUT. And so on up through **nine**. You are to use these tools for producing the numbers needed for calculation, and only these tools. ====pipemath suite==== The pipemath suite is a collection of command-line tools that perform various basic math operations you may find useful for this project. The tools include: * **plus** - addition * **minus** - subtraction * **multby** - multiplication * **divideby** - division * **modulus** - modulus/remainder * **abs** - absolute value * **negate** - negation * **negify** - absolute negation * **sqrt** - square root With the exception of **abs**, **negate**, **negify**, and **sqrt**, all the tools require two inputs (known as a binary operator; note, this is **NOT** saying you need to enter binary numbers into them... they expect decimal values). The first input **MUST** come from STDIN. The second input **MUST** come from the first command-line argument. The tool, with the appropriate inputs, will perform the operation and output its result to STDOUT. The **abs**, **negate**, **negify**, and **sqrt** tools require only one input (known as a unary operator). That input **must** come from STDIN. When given an appropriate input, the operation is performed and will output its result to STDOUT. =====Process===== In the **TASK** file, you will be given a set of tasks you need to construct command-lines for to solve, using the tools provided to you in both the **numbers** and **pipemath** suites. You will also want to make use of pipes and command expansions in your solutions. There will also be result, numbers, operations, minimum pipes, and maximum pipes constraints listed for each problem, which you will need to abide by in order to receive full credit. The potential constraints are as follows: * **ANY:** no restrictions, any in applicable category can be used * **ONLY:** you are restricted to only those listed * **WITH_LIMITS:** usually providing specific restrictions within an **ANY** domain * **EXCEPT:** you are explicitly not allowed to use the listed; usually restricting an existing **ANY** domain There may also be quantity limits on how many times you can use each number or operation. If so, such will be shown in parenthesis following the item in question. Also, no cheating with idle "filler" operations, like "plus 0 | plus 0 | plus 0" to rack up needed pipe counts. As an example, take the following (formatted is it would appear in your **TASK** file): task: 0 result: 4 numbers: ONLY(three(2), five, seven, nine) operations: ANY min_pipes: 2 max_pipes: ANY 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/upf0$ seven | minus `three` 4 lab46:~/src/unix/upf0$ BUT, we see that the **min_pipes** requirement is 2, and we only have 1 here... so we'll need to come up with another solution. How about: lab46:~/src/unix/upf0$ three | minus `seven` | negate 4 lab46:~/src/unix/upf0$ There we go... still got our 4, but this time via the minimum required quantity of pipes. In this case, we'll want to record our command-line 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-line you ran, merely placed in a text file. For example, if you **cat** the file, you should see the following: lab46:~/src/unix/upf0$ cat task0.cli three | minus `seven` | negate lab46:~/src/unix/upf0$ Basically, each task#.cli can be its own script. If we were to execute it, the correct result should be produced. =====upf0steps===== You will once again be creating a steps file that can automate your project. As in previous projects, **upf0steps** will contain the steps you took from the point of copying the numbers suite and downloading the pipemath 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. * For each task, you'll want to display things as follows: * "Task X result is: #" * where X is the task number (0, 1, 2, etc.) * where # is the calculated 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 result is:" text, and there is a single space separating it from the colon. * additionally, your upf0steps file will only create, alter files if run by you. If run by a user who is not you, skip the file manipulation and only output the results. * you will be making use of a loop to drive the execution of your results (the "Task # result is: ..."). For example, a sample output of your **upf0steps** script should appear like follows (but your # values will of course be different based on your individual **TASK** file): lab46:~/src/unix/upf0$ ./upf0steps Task 0 result is: 13 Task 1 result is: 27 Task 2 result is: 32 Task 3 result is: 7 Task 4 result is: -4 Task 5 result is: 57 Task 6 result is: 2 Task 7 result is: 98 lab46:~/src/unix/upf0$ =====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 **upf0steps** file. To submit this project to me using the **submit** tool, run the following command at your lab46 prompt: $ submit unix upf0 upf0steps task*.cli Submitting unix project "upf0": -> upf0steps(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:upf0:final tally of results (78/78) *:upf0:upf0steps has valid list of non-interactive instructions [4/4] *:upf0:upf0steps only copies/alters files if USER matches [4/4] *:upf0:upf0steps builds the various task#.cli files it runs [4/4] *:upf0:upf0steps obtains the latest pipemath release from site [4/4] *:upf0:upf0steps only displays specified STDOUT output [4/4] *:upf0:upf0steps resiliently creates local project directory [4/4] *:upf0:upf0steps copies public dir data with absolute path [4/4] *:upf0:upf0steps makes clear, effective use of wildcards [4/4] *:upf0:upf0steps has descriptive why and how comments [4/4] *:upf0:upf0steps indentation used to promote scope and clarity [2/2] *:upf0:upf0steps defines and uses custom variables [4/4] *:upf0:upf0steps uses command expansions to get information [4/4] *:upf0:upf0steps uses a loop to drive numbers in final output [4/4] *:upf0:upf0steps automates the task when run [4/4] *:upf0:all files are organized, clear, and easy to read [4/4] *:upf0:task#.cli files output only correct, specified data [4/4] *:upf0:task#.cli files use specified number tools by quantity [4/4] *:upf0:task#.cli files display no STDERR output [4/4] *:upf0:task#.cli files have solution within given constraints [4/4] *:upf0:task#.cli files only have the solution command-line [4/4]