% CST8207 Assignment 06 - start-up files, environment variables, quoting % Ian! D. Allen - - [www.idallen.com] % Winter 2014 - January to April 2014 - Updated Sun Mar 9 17:12:13 EDT 2014 Due Date and Deliverables ========================= > **Do not print this assignment on paper!** > > - On paper, you will miss updates, corrections, and hints added to the > online version. > - On paper, you cannot follow any of the [hyperlink URLs] that lead you > to hints and course notes relevant to answering a question. > - On paper, scrolling text boxes will be cut off and not print properly. - **Due Date**: `10h00 (10am) Wednesday March 12, 2014 (middle of Week 9)` - **NEW DUE DATE** - **ANOTHER NEW DUE DATE** - Late assignments or wrong file names may not be marked. Please be accurate and punctual. - **Available online** - Version 1 – 18h00 Sunday February 23, 2014 - Version 2 – 17:40 Sunday March 2, 2014 – due date extended to Week 9 - Version 3 – 08:15 Sunday March 9, 2014 – due date extended again (Blackboard down) - **Prerequisites** - All [Class Notes][hyperlink URLs] since the beginning of term. - All your previous [Assignments]. - An ability to **READ ALL THE WORDS** to work effectively. - **Deliverables** 1. One text file uploaded to Blackboard according to the steps in the [Checking Program] section below. 2. Directory structure created and left for marking on the [Course Linux Server] (**CLS**).\ **Do not delete any assignment work from the CLS until after the term is over!** **WARNING:** Some inattentive students upload Assignment #6 into the Assignment #5 upload area. Don’t make that mistake! Be exact. Purpose of this Assignment ========================== > 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. Introduction and Overview ========================= 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. The Source Directory -------------------- 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. Tasks ===== - Do the following tasks in order, from top to bottom. - These tasks must be done in your account on the [Course Linux Server]. - **READ ALL THE WORDS!** and do not skip steps. - Your instructor will mark on the due date the work you do in your account on the CLS. Leave all your work on the CLS and do not modify it. - **Do not delete any assignment work from the CLS until after the course is over.** Set Up – The Base Directory --------------------------- 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: a. Create the `CST8207-14W` directory in your CLS HOME directory. b. Create the `Assignments` directory in the `CST8207-14W` directory. c. 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. Creating Shell Start-Up Files ----------------------------- 1. Review the [Class Notes]: - [Shell Variables] - [Start-Up Files] 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. Working with directories and files ---------------------------------- 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. Finding multiple files in a maze using a GLOB pattern ----------------------------------------------------- 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. Finding information in the course notes --------------------------------------- 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. Scanning the Log File --------------------- 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 188) 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. Using shell environment variables --------------------------------- 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. Quoting Exercise – Easy Version ------------------------------- 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. When you are done ----------------- 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. Checking, Marking, and Submitting your Work =========================================== **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. a) Verify that your latest submission has the correct 16-character, lower-case file name beside the *Attached Files* heading. b) The *Submission Field* and *Student Comments* headings must be **empty**. (I do not read them.) c) **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!** - I do not accept any assignment submissions by email. Use only the Blackboard *Attach File*. No word processor documents. Plain Text only. - Use the *exact* file name given above. Upload only one single file of plain text, not HTML, not RTF, not MSWord. No fonts, no word-processing. Plain text only. - Did I mention that the format is plain text (VIM/Nano/Pico/Gedit or TextEdit or Notepad)? - **NO EMAIL, WORD PROCESSOR, PDF, RTF, or HTML DOCUMENTS ACCEPTED.** - No marks are awarded for submitting under the wrong assignment number or for using the wrong file name. Use the exact 16-character, lower-case name given above. - WARNING: Some inattentive students don’t read all these words. Don’t make that mistake! Be exact. **READ ALL THE WORDS. OH PLEASE, PLEASE, PLEASE READ ALL THE WORDS!** -- | 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 [www.idallen.com]: http://www.idallen.com/ [hyperlink URLs]: indexcgi.cgi#XImportant_Notes__alphabetical_order_ [Assignments]: indexcgi.cgi#XAssignments [Checking Program]: #checking-marking-and-submitting-your-work [Course Linux Server]: 070_course_linux_server.html [Start-Up Files]: 350_startup_files.html [Shell Variables]: 320_shell_variables.html [Worksheet #2 HTML]: worksheet02.html [Non-interactive shells and PS1]: 350_startup_files.html#non-interactive-shells-and-ps1 [Source Directory]: #the-source-directory [Copies of the CST8207 Course Notes]: 070_course_linux_server.html#copies-of-the-cst8207-course-notes [Quoting]: 440_quotes.html [`argv.sh`]: 440_quotes.html#using-argv.sh-to-count-command-line-arguments [File Transfer]: 015_file_transfer.html [email]: mailto:idallen@idallen.ca [Plain Text]: assignment06.txt [Pandoc Markdown]: http://johnmacfarlane.net/pandoc/