User Tools

Site Tools


Sidebar

projects

uxi0 (due 20190123)
wcp1 (due 20190123)
adm0 (due 20190130)
wcp2 (due 20190130)
pbx0 (due 20190206)
wcp3 (due 20190206)
pbx1 (due 20190213)
wcp4 (due 20190213)
pbx2 (due 20190227)
wcp5 (due 20190227)
upf0 (due 20190306)
wcp6 (due 20190306)
wpa0 (due 20190313)
wcp7 (due 20190313)
spf0 (due 20190321)
wcp8 (due 20190320)
upf1 (due 20190327)
wcp9 (due 20190327)
usr0 (due 20190410)
wcpA (due 20190410)
pct0 (due 20190417)
wcpB (due 20190417)
pwn0 (due 20190424)
wcpC (due 20190424)
spf1 (due 20190501)
EoCE - bottom of journal (due 20190514-172959)
haas:spring2019:unix:projects:spf1

This is an old revision of the document!


Corning Community College

CSCS1730 UNIX/Linux Fundamentals

Project: SCRIPTING PRODUCTIVITY FUN (spf1)

Errata

  • any bugfixes or project updates will be posted here

Toolbox

In addition to the tools you're already familiar with, it is recommended you check out the following tools for possible application in this project (you may not need to use them in your solution, but they definitely offer up functionality that some solutions can make use of):

  • basename(1)
  • bc(1)
  • cut(1)
  • diff(1)
  • grep(1)
  • mktemp(1)
  • sed(1)
  • tr(1)
  • wc(1)

Objective

To create a set of scripts that operate the sequence of LEDs located on the raspberry pi + breadboard setups located at each pod table.

In a group, you will be creating:

  • an initialization script
  • an incrementing 8-bit binary counter (0-255)
  • a decreminting 8-bit binary counter (255-0)
  • a strobing light sequence (back and forth)

Accessing the Raspberry Pi

At each pod table is a dedicated raspberry pi 1 model B, interfaced with a breadboard and an array of eight LEDs, each wired up individually to a Raspberry Pi general purpose I/O pin.

Using the 'WiringPi' interface (a software library that also provides some command-line commands, such as the gpio tool), we can interact with these I/O pins for purposes of input and output.

Getting started: logging in

Locating the appropriate pi (the one situated at your table), you will want to ssh into it from a pod or lab46 terminal.

There are four of these systems, numbered as follows:

  • pi1b_00 - pod0# table, right corner by white board
  • pi1b_01 - pod1# table, left corner by white board (and my office)
  • pi1b_02 - pod2# table, by the main door to the room
  • pi1b_03 - pod3# table, by the back corner / small whiteboard

Each pi is equipped with a standard raspbian release of Linux (one of the default distributions for the raspberry pi), default user credentials unchanged, so to access we have:

  • username: pi
  • password: raspberry

You will need to ssh into the geographically appropriate pi (shared by your group)

lab46:~$ ssh pi@pi1b_0#

NOTE that, just like the first time you accessed lab46, you will likely be prompted to approve the connection (“authenticity of host cannot be established” message) by answering the full “yes” and hitting enter, before being prompted for the password.

Getting a readout of the GPIO pins

Using the gpio tool on the pi in question, we can obtain the current status of the GPIO pins on the pi with the readall parameter; output will appear as follows:

pi@pi1b_0#:~ $ gpio readall
 +-----+-----+---------+------+---+-Model B1-+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+-Model B1-+---+------+---------+-----+-----+

When using the gpio tool, we are specifically interested in the “wPi” columns.

Assembly of LED circuits

The eight LED circuits established on each pi are hooked into a unique GPIO (wiring pi numbers 0-7).

When the pin is active (3.3V applied, the 'true' or 1 state), the LED will be lit up (turned ON).

When the pin is inactive (0V applied, the 'false' or 0 state), the LED will be OFF.

Configuring GPIO pins for use with our LEDs

If you look in the table for wiringPi pins 0-7, you'll see under the “Mode” column that all the needed pins are set to IN or “input” mode (expecting to read data in).

To utilize the LEDs, we need to instead OUTPUT from the pins.

A mode change is needed, which can be accomplished with the gpio command, mode parameter. It requires the wiringPi pin number (0-7), and the desire mode to set it to (in, out).

To set wiringPi GPIO pin 0 for output mode, for instance, we'll want to do this:

pi@pi1b_0#:~ $ gpio mode 0 out

You may want to repeat (or loop) this for the remaining pins.

Writing to the GPIO pin

To modify the state of the pin (it can be in a '0' or '1' state), we once again use the gpio command, with the write parameter. It requires the wiringPi pin number (0-7) and the state we wish it to become (0 is OFF, or 1 being ON).

To write a 1 to wiringPi GPIO pin 0, we'll want to do this:

pi@pi1b_0#:~ $ gpio write 0 1

Similarly, to turn it back off again, we'll want to write a zero there:

pi@pi1b_0#:~ $ gpio write 0 0

You will want to perform similar actions on the other LED-wired pins to create the desired situations as required by this project.

Process

It is your task to write 4 scripts, specifications laid out as follows:

script1: pigen

You are to write a script, called and submitted by the name pigen (no extension, although it is to be a bash script, with proper shabang, comments, and solution).

By default, if you run the script by itself, it should calculate and produce (in a file in the current directory), a file by the name of pi.100.out, which will contain the first 100 digits of PI (lacking the period '.' that separates the 3 from the rest of the irrational number):

lab46:~/src/unix/spf0$ ./pigen
lab46:~/src/unix/spf0$ ls
pi.100.out  pigen
lab46:~/src/unix/spf0$ cat pi.100.out
3141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067
lab46:~/src/unix.spf0$ 

If you provide a command-line argument, it must be a valid numeric value between 1 and 2000, and will calculate that many digits of PI, saving it in a file pi.#.out, where # is the number of digits requested.

You also need to verify your results against the PI digit database on lab46 (do not copy this file… set a variable to it for easy access), and display the message “MISMATCH” if your calculated/processed results do NOT match the validated PI computation out to that indicated quantity of spaces.

Additionally:

  • Your script is to only produce a pi.#.out file in the current directory.
    • ANY temporary files need to be created in (and subsequently removed from) the /tmp directory, of a relatively unique name autogenerated by the mktemp(1) tool.

script2: pigrep

Your second script will be called pigrep (no extension, although it is to be a bash script, with proper shabang, comments, and solution), and will perform searches on a pigen-generated pi.#.out file for specified patterns (numerical substrings) within the generated digits.

By default, if you run the script by itself, it should generate the following error (and exit with a non-zero value):

lab46:~/src/unix/spf0$ ./pigrep
ERROR: must specify PATTERN
lab46:~/src/unix/spf0$ 

It will have online usage information, displayed when the 'help' option is provided anywhere on the pigrep command-line:

lab46:~/src/unix/spf0$ ./pigrep help

 pigrep - search available pi digits via regex for matches;
          must be part of pipeline (send PI digits in via STDIN)

   usage: pigrep [OPTION...] PATTERN

    note: if MAX variable is set, cap processing at that value

 options:

  atend - calculations are based on last digit of match
 byline - output one value per line (default is space-separated)
  drop3 - do not include leading 3 of pi (*3*14) in processing
 offset - determine offsets of matches (from start of digits)
   help - display this help and exit

lab46:~/src/unix/spf0$ 

Your script should also take the following arguments (in this order):

  • required argument:
    • PATTERN: a string containing the numeric pattern you are looking for.
      • for example: '76'
  • optional arguments:
    • atend: by default, offset calculations are based on the first (left-most) digit of the pattern; with this option, compute the offset based on the last (right-most) digit of the pattern
      • atend is meant to be used in conjunction with offset, by itself it does not alter default processing
    • byline: by default, matches are space-separated. With this option, display one match per line
    • drop3: do not include the leading 3 of PI in processing
    • offset: determine offsets of matches from start of digits
    • help: display usage information

You are also to check for the existence of a MAX variable, and if set to a valid, positive non-zero decimal (base 10) number, will cap the amount of results it processes / outputs.

Numerical arguments are to be given as valid, positive non-zero decimal (base 10) values.

With any of these arguments validly provided, they should adjust the script's processing and output accordingly.

Also to keep in mind:

  • Your script is not to produce any files as a result of operating.
    • If your solution calls for ANY temporary files, they need to be created in (and subsequently removed from) the /tmp directory, and be of a relatively unique name autogenerated by the mktemp(1) tool.

Some sample outputs follow:

Only specifying numeric pattern

In the event only a pattern is provided, search through the PI data for the provided pattern, displaying each match to STDOUT.

For example:

lab46:~/src/unix/spf0$ cat pi.120.out | ./pigrep '26'
26 26 
lab46:~/src/unix/spf0$ 

one result per line

Using the byline option, instead of displaying results horizonally, they'll be displayed vertically (one result per line) to STDOUT.

lab46:~/src/unix/spf0$ cat pi.120.out | ./pigrep '26' byline
26 
26 
lab46:~/src/unix/spf0$ 

compute offsets from start of digits

The offset argument will, instead of displaying the numeric matches (which, aside from counting are of dubious value) will display how many digits away from the start of the PI digits the pattern resides.

lab46:~/src/unix/spf0$ cat pi.120.out | ./pigrep '26' offset
7 22 
lab46:~/src/unix/spf0$ 

With an example like this, we should easily be able to verify its correctness:

lab46:~/src/unix/spf0$ cat pi.120.out
314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664
lab46:~/src/unix/spf0$ cat pi.120.out | cut -c7-8,22-23
2626
lab46:~/src/unix/spf0$ 

mixing options (offset, byline)

And we can mix options (in any order):

lab46:~/src/unix/spf0$ cat pi.120.out | ./pigrep byline '26' offset 
7 
22 
lab46:~/src/unix/spf0$ 

Using atend with offset

The atend option, issued by itself, has no impact on operations:

lab46:~/src/unix/spf0$ cat pi.120.out | ./pigrep atend '26'        
26 26 
lab46:~/src/unix/spf0$ 

So we need to combine it with the offset option to make an impact:

lab46:~/src/unix/spf0$ cat pi.120.out | ./pigrep atend offset '26' 
8 23 
lab46:~/src/unix/spf0$ 

dropping the leading 3

With the drop3 option, we merely exclude the leading 3 of pi from our calculations. This should result in everything being “off by one” from previous outputs (with any combination of arguments):

lab46:~/src/unix/spf0$ cat pi.120.out | ./pigrep atend offset '26' drop3
7 22 
lab46:~/src/unix/spf0$ 

Using MAX to limit processing

Sometimes, a pattern may produce an untenable quantity of results. We may wish to restrict it, and can do so with the aid of setting the MAX variable.

Take this request, which produces numerous results:

lab46:~/src/unix/spf0$ cat pi.120.out | ./pigrep '2'                    
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 
lab46:~/src/unix/spf0$ 

We can cut that down to a smaller quantity by setting MAX accordingly (let's say, limit to 4 matches):

lab46:~/src/unix/spf0$ cat pi.120.out | MAX=4 ./pigrep '2'
2 2 2 2 
lab46:~/src/unix/spf0$ 

You could also export MAX, mitigating the need to manually specify it for each run.

Specifications

Evaluation will be based on correctness of values as well as on formatting/spacing.

You'll notice that everything lines up and is positioned similarly:

  • groupwork! This project is specifically designed to be performed in groups.
    • I want to see groups ranging from a minimum of 2 people, to a maximum of 4 people. Any less and any more are not allowed.
    • EVERY group member needs to be identified in your scripts (in a comment listing everyone).
    • EVERY group member needs to be familiar with the end products
    • EVERY group member needs to submit a copy of the scripts (they should all be identical- I will check)
      • in the event you feel other group members have not lived up to their obligations, you may alter your scripts accordingly (be it not giving them the final product, or enhancing functionality to bring it in compliance, or leaving comments indicating who wasn't pulling their own weight).
    • EVERY group member needs to do an approximately equal portion of the work. Slackers should be called out (I'll be keeping an eye out as well) and they will lose credit.
    • This project is designed to be done DURING class time. It may offer up some useful insights into other projects (that you're doing on your own).
  • You need to check your arguments to ensure they are present and valid.
    • all mentioned arguments implementing their indicated functionality (atend, byline, drop3, offset, help)
      • help takes priority over other options
      • atend has no appreciable impact unless offset is also specified
    • any invalid arguments should be silently dropped/ignored.
  • your script needs to commence with a proper shabang to run using bash; your script needs to end with an “exit 0” at the very end
  • comments and indentation are required and necessary
    • comments should explain how or why you are doing something
    • indentation should be consistent throughout the script (no mixing of different indentation units; no mixing of tabs and spaces)
    • indentation is to be no less than 3 on-screen spaces (I recommend tabstops of 4).
  • continuing with our shell scripting, your scripts will need to employ in a core/central way (note that both scripts may not each need all of these, but across both scripts, you should make sure that each of these concepts is utilized):
    • variables
    • command-line argument parsing and usage
    • command-line pipelines
    • command expansions
    • regular expressions
    • conditional/selection structures
    • loops
  • your logic needs to:
    • flow (one thing leads into the next, as best as possible)
    • make sense within the given context
    • avoid redundancy
    • be understood by you, and everyone in your group (no grabbing snippets that seem to “work” from the internet)
      • if you gain inspiration from some external resource, please cite it
      • comments are a great way of demonstrating understanding (if you explain the why and how effectively, and it isn't in violation of other aspects, I'll know you are in control of things)

To be sure, I'll be checking to make sure you solution follows the spirit of what this project is about (that you implement functional, flowing logic utilizing the tools and concepts we've learned, in an application that helps demonstrate your comprehension). Don't try to weasel your way out of this or cut corners. This is an opportunity to further solidify your proficiency with everything.

Spirit of project

The spirit of the project embodies many aspects we've been focusing on throughout the semester:

  • recognizing patterns to employ effective solutions in problem solving
  • utilizing concepts and tools covered
  • demonstrating comprehension of concepts, tools, and problems
  • employing concepts in knowledgeable and thoughtful manner
  • following instructions
  • implementing to specifications
  • utilizing creativity
  • being able to control solution via consistent, clear, and organized presentation
  • approximately equal involvement and impact of all group members on the brainstorming and development of the finished scripts.

Basically: I want your solution to be the result of an honest, genuine brainstorming process where you have figured out a path to solving the problem, you have dabbled and experimented and figured things out, and you can command the concepts and tools with a fluency enabling you to pull off such a feat. Your solution should demonstrate the real learning that took place and experience gained.

Cutting corners, avoiding work, skimping on functionality, cheating through getting others to do work for you or finding pre-packaged “answers” on the internet violates the spirit of the project, for they betray your ability to pull off the task on your own.

Identifying shortcomings

I would also like it if you provided an inventory of what functionality is lacking or out of spec when you submit the project. The better you can describe your deviations from stated requirements, the more forgiving I may be during evaluation (versus trying to hide the shortcomings and hoping I do not discover them).

The more fluent you are in describing your shortcomings on accomplishing the project (ie “I didn't know how to do this” is far from fluent), the better I will be able to gauge your understanding on a particular aspect.

This can be in the form of comments in your script, or even a separate file submitted at time of submission (if a file, be sure to make mention of it in your script so I can be sure to look for it).

Submission

By successfully performing this project, you should have a fully functioning set of scripts by the names pigen and pigrep, which are all you need to submit for project completion (no steps file, as your “steps” file ARE the scripts you wrote).

To submit this project to me using the submit tool, run the following command at your lab46 prompt:

$ submit unix spf0 pigen pigrep
Submitting unix project "spf0":
    -> pigen(OK)
    -> pigrep(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:

26:spf0:final tally of results (26/26)
*:spf0:scripts effectively utilize variables in operations [2/2]
*:spf0:scripts effectively utilize command-line arguments [2/2]
*:spf0:scripts effectively utilize command expansions [2/2]
*:spf0:scripts effectively utilize regular expressions [2/2]
*:spf0:scripts effectively utilize selection structures [2/2]
*:spf0:scripts effectively utilize looping structures [2/2]
*:spf0:scripts are proper bash scripts with shabang and exit [2/2]
*:spf0:pigrep displays values in proper orientation [2/2]
*:spf0:pigrep accurately displays values as requested [2/2]
*:spf0:scripts properly manage input violations [2/2]
*:spf0:pigen operates according to specifications [2/2]
*:spf0:pigrep operates according to specifications [2/2]
*:spf0:script logic is organized and easy to read [2/2]

Additionally:

  • Solutions not abiding by spirit of project will be subject to a 25% overall deduction
  • 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
  • Solutions not done in a valid group will be subject to a 25% overall deduction
haas/spring2019/unix/projects/spf1.1555429669.txt.gz · Last modified: 2019/04/16 15:47 by wedge