Updated: 2014-03-09 17:12 EDT

1 Due Date and DeliverablesIndexup to index

Do not print this assignment on paper!

WARNING: Some inattentive students upload Assignment #6 into the Assignment #5 upload area. Don’t make that mistake! Be exact.

2 Purpose of this AssignmentIndexup to index

Do not print this assignment on paper. On paper, you cannot follow any of the hyperlink URLs that lead you to hints and course notes relevant to answering a question.

This assignment is based on your weekly Class Notes.

  1. Create your Start-Up Files profile files with optional sysadmin aliases and options.
  2. Perform some simple system administration tasks.
  3. Practice with GLOB and I/O redirection.
  4. Use fgrep and grep patterns to search the course notes for keywords.
  5. Study shell quoting and fix the quoting in a broken shell script.
  6. Transfer and submit a file to Blackboard.

Remember to READ ALL THE WORDS to work effectively and not waste time.

3 Introduction and OverviewIndexup to index

This is an overview of how you are expected to complete this assignment. Read all the words before you start working.

  1. Complete the Tasks listed below.
  2. Verify your own work before running the Checking Program.
  3. Run the Checking Program to help you find errors.
  4. Submit the output of the Checking Program to Blackboard before the due date.
  5. READ ALL THE WORDS to work effectively and not waste time.

You will create file system structure in your CLS home directory containing various directories and files. You can use the Checking Program to check your work as you do the tasks. You can check your work with the checking program as often as you like before you submit your final mark. Some task sections below require you to finish the whole section before running the checking program; you may not always be able to run the checking program successfully after every single task step.

Use a text editor to create your Start-Up Files login profile files .bashrc and .bash_profile.

Do some system administration tasks similar to Assignment #04.

When you are finished the tasks, leave these files, directories, and links in place on the CLS as part of your deliverables. Do not delete any assignment work from the CLS until after the term is over!

Assignments may be re-marked at any time on the CLS; you must have your term work available on the CLS right until term end.

3.1 The Source DirectoryIndexup to index

All references to the “Source Directory” below are to the CLS directory ~idallen/cst8207/14w/assignment06/ and that name starts with a tilde character ~ followed by a userid with no intervening slash. The leading tilde indicates to the shell that the pathname starts with the HOME directory of the account idallen (seven letters).

You do not have permission to list the names of all the files in the Source Directory, but you can access any files whose names you already know.

4 TasksIndexup to index

4.1 Set Up – The Base DirectoryIndexup to index

  1. Create the following directory structure starting in your CLS HOME directory and record (for study purposes) the series of Unix commands you used to create it. (You do not have to create any directories that you have already created in a previous assignment.) Spelling and capitalization must be exactly as shown:
    1. Create the CST8207-14W directory in your CLS HOME directory.
    2. Create the Assignments directory in the CST8207-14W directory.
    3. Create the assignment06 directory in the Assignments directory.

The correct directory tree will look similar to the ASCII tree diagram below. The spelling and capitalization must be exactly as shown.

CST8207-14W
`-- Assignments
    `-- assignment06

This assignment06 directory is the base directory for most pathnames in this assignment. Store your files and answers below in this base assignment06 directory.

Run the Checking Program to verify your work so far.

4.2 Creating Shell Start-Up FilesIndexup to index

  1. Review the Class Notes:
  2. Use a Linux text editor to create your .bash_profile and .bashrc files with the minimum suggested content described in the page Start-Up Files. (Your .bash_profile must contain only one line. Your .bashrc must contain at least two lines.)

    Do not set any options or aliases in your .bashrc that you do not understand! If you don’t know the meaning of a setting, don’t use it. You can RTFM in the bash man page for all BASH settings, and RTFM in command man pages to learn about options to commands.

    I will be spot-checking your knowledge of your aliases. Students using aliases they don’t understand will experience much confusion trying to do future assignments. Only use aliases you understand.

    Using the PS1 variable from Worksheet #2 HTML, set your prompt to include your user name, your computer name, and the basename of your current working directory. Put this setting in your .bashrc file.

  3. Verify that nothing prints on your screen after you enter your password when you run the non-interactive shell connection using ssh localhost true (as described in the section on Non-interactive shells and PS1:

    $ ssh localhost true
    *** COURSE LINUX SERVER ***
    user@localhost's password:
    $

    For non-interactive commands to work properly, there must be no output on your screen after you enter your password using the above non-interactive command line using the true command.

Your instructor will mark the .bashrc and .bash_profile files in your account on the assignment due date. Do not upload them to Blackboard. Leave them there on the CLS. Do not delete anything.

Run the Checking Program to verify your work so far.

4.3 Working with directories and filesIndexup to index

  1. Make a copy of the base3 directory from Assignment #04 into the base directory of this assignment using the name basecopy here. Remember to preserve file attributes when you copy.

  2. Rename all the directories by changing every occurrence of bdir to just dir in every pathname, e.g. basecopy/bdir2/bdir2-1/MT2-1 becomes basecopy/dir2/dir2-1/MT2-1.

  3. Make basecopy your current directory and redirect the ten lines of recursive find output into the file named basecopyfind.txt in your base directory (not in the current directory). The word count of this file must be: 10 10 112

Run the Checking Program to verify your work so far.

4.4 Finding multiple files in a maze using a GLOB patternIndexup to index

  1. Under the Source Directory there is a name maze that is a symbolic link that leads to the same directory maze used in a previous assignment: Assignment #04 HTML.

    In the maze use a single command (not a pipeline) to recursively find all pathnames with a basename that begins with your eight-character userid at the start of the name. For example, if your userid were abcd0001 then you might output pathnames containing basenames such as abcd0001 and abcd0001YYY but not XXXabcd0001 or XXXabcd0001YYY where XXX and YYY can be anything (zero or more characters). You will find exactly 15 pathnames.

  2. Modify the same single command you used to find the names above and instead use the option that makes the command show the full information about the names (including permissions, owner, size, date, etc.) instead of just the pathname. You will know you have the right option if the output of the command shows 15 lines and 168 words.

  3. Pipe the pathname output of the above command (15 lines of output) into a sorting program and put the reverse-sorted output into file mazefoundreverse.txt under your base directory. The reverse-sorted file will still contain 15 lines and 168 words.

Run the Checking Program to verify your work so far.

4.5 Finding information in the course notesIndexup to index

  1. Use the options to fgrep that ignore case and “show files with matches” (RTFM) and find the 23 file names that contain the exact string symbolic link in all the files ending in .txt in the previous term course notes. Exactly 23 file names will print, and one of the pathnames will end in basename 750_booting_and_grub.txt. Hint: Use the oldnotes symbolic link from Assignment #04 and a GLOB pattern that matches all the .txt files under it, using the fgrep method described in Copies of the CST8207 Course Notes.

  2. Now redirect the 23 names into file symlinkfound.txt under your base directory. The file must contain 23 lines ending in the .txt suffix.

Run the Checking Program to verify your work so far.

4.6 Scanning the Log FileIndexup to index

  1. Use a two-command pipeline to find every line containing the string new denied hosts that appears in January in the denyhosts log file. (This log file is in the same directory as the auth.log file used in class.) You should find 188 matching lines in the file. (Hint: See your class notes from Week 05 Notes. How do you know which lines in the denyhosts file were created in January?)

  2. Add one more command to the pipeline (making a total of three commands) to extract only the blank-separated field containing the IP address from each of the above 188 matching lines. (Hint: See your class notes from Week 05 Notes.) The first line (of
    1. will be ['50.46.204.2'] and the last line (of 188) will be ['222.186.62.56'].
  3. Put a copy of the three-command pipeline into file denygrep.sh in the base directory. (Put the command pipeline in the file, not the output of the command.) If you execute sh ./denygrep.sh the output should word count as 188 lines and 188 words, with either 3372 or 3373 characters (depending on how you extracted the IP address field).

Run the Checking Program to verify your work so far.

4.7 Using shell environment variablesIndexup to index

Follow correct double-quoting procedures when expanding variables, as noted in Shell Variables.

  1. Display the value of the environment variable containing your userid. Put the command you use to do this into file env.sh in the base directory. (Put in the command, not the output.) The file will contain one command line.

  2. Display the value of the environment variable containing your home directory. Append the command you use to do this to file env.sh in the base directory. (Put in the command, not the output.) The file will contain two command lines.

  3. Display the value of the environment variable containing your assigned shell. Append the command you use to do this to file env.sh in the base directory. (Put in the command, not the output.) The file will contain three command lines.

  4. Display the value of the environment variable containing your shell search path. Append the command you use to do this to file env.sh in the base directory. (Put in the command, not the output.) The file will contain four command lines.

  5. Run sh ./env.sh and the values of all four environment variables should display on your screen.

Run the Checking Program to verify your work so far.

4.8 Quoting Exercise – Easy VersionIndexup to index

  1. Make the above assignment06 base directory your current directory.

  2. Copy the script file quotes.sh from the Source Directory into the current directory.

  3. Execute this file (enable execute permissions and then run it) or use bash to read the file so that all the commands inside it execute:

    $ chmod ugo+x quotes.sh
    $ ./quotes.sh
    ** - OR USE BASH: - **
    $ bash ./quotes.sh
  4. Note that the output of running the script generates an error message and doesn’t match what is written in the script file. (For example: many quotes are missing, GLOB characters and variables are expanding, and the spacing of the words is different.)

    Fix the Quoting inside the file so that every line is fully quoted to appear exactly as written in the file, blanks included, with no meta-character expansion by the shell. The correct output should give eight lines and look exactly like this when you are finished (including all the extra spaces between some of the words):

    Where is the question mark after the file /etc/group?
    Is one also missing after /etc/passwd?
    The shell prompt is contained in the  $PS1  variable.
    This line isn't appearing on my screen properly.  It's missing the quotes.
    This line is also "missing" all the quotes.  It is not "right" yet.
    This is also "missing" all quotes.  It's output that doesn't make sense.
    This isn't working either.  The shell gives an error message.
    ***  This is a file to practice shell quoting.  Do you see this line?  ***

    You must edit the file to make the entire line of text on each line one single shell argument to echo. You can check your success by temporarily substituting the argv.sh program from the Class Notes for the echo command. (You have to put the argv.sh program into the same directory as quotes.sh under the name argv.sh and make it executable. Read the quotes.sh file for details on using an alias inside the quotes file to run this program. Remember to return the script to using only echo after you finish your testing.)

    You’ll know you got it mostly right when you see this wc and sum output (but you’ll need to verify one-argument-per-echo using the argv.sh program):

    $ ./quotes.sh | wc
    8 86 500
    $ ./quotes.sh | sum
    39574   1

    If your line and word count is correct but the number of characters is less, you probably failed to make the entire text one argument to echo on each line. You must use Quoting to hide all the blanks and special characters from the shell on each of the lines. The argv.sh program will tell you if you got it right.

  5. When the edited script output is correct, run the script and redirect the script output into file quotesout.txt

Run the Checking Program to verify your work so far.

4.9 When you are doneIndexup to index

That is all the tasks you need to do.

Check your work a final time using the Checking Program and save the output as described below. Submit your mark following the directions below.

5 Checking, Marking, and Submitting your WorkIndexup to index

Summary: Do some tasks, then run the checking program to verify your work as you go. You can run the checking program as often as you want. When you have the best mark, upload the marks file to Blackboard.

Since I also do manual marking of student assignments, your final mark may not be the same as the mark submitted using the current version of the Checking Program. I do not guarantee that any version of the Checking Program will find all the errors in your work. Complete your assignments according to the specifications, not according to the incomplete set of the mistakes detected by the Checking Program.

  1. There is a Checking Program named assignment06check in the Source Directory on the CLS. You can execute this program by typing its (long) pathname into the shell:

    $ ~idallen/cst8207/14w/assignment06/assignment06check

  2. Execute the above “check” program. This program will check your work, assign you a mark, and display the output on your screen. (You may want to paginate the long output so you can read all of it.)

    You may run the “check” program as many times as you wish, to correct mistakes and get the best mark. Some task sections require you to finish the whole section before running the checking program at the end; you may not always be able to run the checking program successfully after every single task step.

  3. When you are done with checking this assignment, and you like what you see on your screen, redirect the output of the Checking Program into the text file assignment06.txt under your assignment06 directory on the CLS. Use the exact name assignment06.txt in your assignment06 directory. Case (upper/lower case letters) matters. Be absolutely accurate, as if your marks depended on it. Do not edit the file.
    • Make sure the file actually contains the output of the checking program!
    • The last text line of the file should begin with: YOUR MARK for
    • Really! MAKE SURE THE FILE HAS YOUR MARKS IN IT!
  4. Transfer the above assignment06.txt file from the CLS to your local computer and verify that the file still contains all the output from the checking program. Do not edit this file! No empty files, please! Edited or damaged files will not be marked. You may want to refer to your File Transfer notes.
    • Make sure the file actually contains the output of the checking program!
    • The last text line of the file should begin with: YOUR MARK for
    • Really! MAKE SURE THE FILE HAS YOUR MARKS IN IT!
  5. Submit the assignment06.txt file under the correct Assignment area on Blackboard (with the exact name) before the due date. Upload the file via the assignment06 “Upload Assignment” facility in Blackboard: click on the underlined assignment06 link in Blackboard. Use “Attach File” and “Submit” to upload your plain text file.

    No word-processor documents. Do not send email. Use only “Attach File”. Do not enter any text into the Submission or Comments boxes on Blackboard; I do not read them. Use only the “Attach File” section followed by the Submit button. If you need to comment on any assignment submission, send me email.

    You can upload the file more than once; I only look at the most recent. You must upload the file with the correct name; you cannot correct the name as you upload it to Blackboard.

  6. Verify that Blackboard has received your submission: After using the Submit button, you will see a page titled Review Submission History that will show all your submissions.
    1. Verify that your latest submission has the correct 16-character, lower-case file name beside the Attached Files heading.
    2. The Submission Field and Student Comments headings must be empty. (I do not read them.)
    3. Save a screen capture showing the uploaded file name. If there is an upload missing, you will need this to prove that you uploaded the file.

    You will also see the Review Submission History page any time you already have an assignment attempt uploaded and you click on the underlined assignment06 link.

    You cannot delete an assignment attempt, but you can always upload a new version. I only mark the latest version.

  7. Your instructor may also mark files in your directory in your CLS account after the due date. Leave everything there on the CLS. Do not delete any assignment work from the CLS until after the term is over!

READ ALL THE WORDS. OH PLEASE, PLEASE, PLEASE READ ALL THE WORDS!

Author: 
| Ian! D. Allen  -  idallen@idallen.ca  -  Ottawa, Ontario, Canada
| Home Page: http://idallen.com/   Contact Improv: http://contactimprov.ca/
| College professor (Free/Libre GNU+Linux) at: http://teaching.idallen.com/
| Defend digital freedom:  http://eff.org/  and have fun:  http://fools.ca/

Plain Text - plain text version of this page in Pandoc Markdown format

Campaign for non-browser-specific HTML   Valid XHTML 1.0 Transitional   Valid CSS!   Creative Commons by nc sa 3.0   Hacker Ideals Emblem   Author Ian! D. Allen