========================================================== Assignment #09 - setting permissions, quoting, linking ========================================================== - Ian! D. Allen - idallen@idallen.ca - www.idallen.com Read *all* the words in this assignment before you begin to type. Available online: Thursday October 25, 2012 CLS: "Course Linux Server" Goals: Practice creating structure and changing permissions. Practice quoting strings as command line arguments. Practice creating hard and soft links to files. Deliverables and due date: DUE: Noon on Monday November 5, 2012 1. Upload the assignment09.txt file. 2. Create the correct files on the CLS under $HOME/assignment09 Late assignments or wrong file names may not be marked. Be accurate. File Submission method: The upload file must have the *exact* name: assignment09.txt Upload the file via the assignment09 "Upload Assignment" facility in Blackboard in a manner similar to how you submitted the previous assignments (but upload under assignment09). Be exact! WARNING: Some inattentive students upload Assignment #09 into the Assignment #8 upload area. Don't make that mistake! Be exact. ============================================================================== Synopsis - This is what you are going to Do -------------------------------------------- On the Course Linux Server, create some directory and file structure containing files and directories with the given permissions. Record the numeric (octal) permissions of each of the directories and files you create in the given record file. Run the checking program to verify your permissions after you have created and recorded everything. You can run the check program as often as you want, until you have fixed things to be perfect. Save the output of the checking program in your own file and then submit the file to Blackboard. All references to things under assignment09/ below refer to a new directory that you create in your HOME directory on the CLS, just as you have done for your other assignments. All references to the "Source Directory" below are to the directory ~idallen/cst8207/12f/assignment09/ Part A - A file to record your permissions ========================================== You need to record the permissions you set on each of the directories and files you create, below. You will record these permissions by copying and editing a file that you get from your instructor. You can record each of the permissions as you create things, or you can record all of the permissions after you have finished, before you run the checking program. A1. Copy the file record.txt from the Source Directory into your own file assignment09/abcd0001.txt where the text abcd0001 is replaced by your *own* eight-character userid in the file name. A2. Edit your copy of the file with vim. Replace each string of three underscores in the file with the correct three-digit numeric (octal) permission value that you record below. Do not change anything else in the file. Note the word count at the bottom of the file. Your count must match. Part B - Creating structure with permissions ============================================ Now you will create some directories and files, then set the correct permissions on them. The permissions to set are described below. Because you are applying permissions to directories as a non-root user, be careful not to lock yourself out of directories by restricting permissions on them too soon - first create all the file and directory structure from the top of the directory tree down, and then apply restrictive permissions afterward from the bottom of the tree upward. If you don't apply permissions last, from the bottom up, you will deny yourself permissions that will prevent you from entering some directories lower down. Assign permissions from the bottom toward the top. B1. Create directory "assignment09/top". a) Directory "top" has no permissions for others. The group can use ls to see the content, but cannot create files or cd into the directory. The user has full permissions. Record the permissions for "top". B2. Underneath directory top create three single-letter directories named: u g o a) Directory u has no permissions for group or other. The user can cd into it, but cannot create any new content nor use ls to see any files in it. Record the permissions. b) Directory g has no permissions for user or other. The group can cd into it and use ls in it, but cannot create any new content. Record the permissions. c) Directory o has no permissions for user or group. Others have full permissions. Record the permissions. B3. Underneath directory u create three single-letter files named: r w x a) None of the files have any permissions for group or other. b) File r has read permission (only) for the user. Record the permissions. c) File w has write permission (only) for the user. Record the permissions. d) File x has execute permission (only) for the user. Record the permissions. B4. Underneath directory g create three two-letter files named: rw wx rx a) None of the files have any permissions for user or other. b) File rw has read and write permission (only) for the group. Record the permissions. c) File wx has write and execute permission (only) for the group. Record the permissions. d) File rx has read and execute permission (only) for the group. Record the permissions. B5. Underneath directory o create three three-character files named: rwx ??? *** (Some characters are meta-characters that are special to the shell and will need careful handling. See the Course Notes about Quoting.) a) None of the files have any permissions for user or group. b) File rwx has full permissions for other. Record the permissions. c) File ??? has no permissions for other. Record the permissions. d) File *** has only read permission for other. Record the permissions. Remember to read all the words above about working from top to bottom and then from bottom to top in this Part. Part C - Quoting exercise ========================= C1. Copy the script file test.sh from the Source Directory into your own file assignment09/test.sh and make it executable. C2. Execute this script file and note that the output doesn't match what is written in the file. Fix the quoting inside the file so that every line appears exactly as written, with no meta-character expansion by the shell. The correct output should give eight lines and look like this when you are finished: Where is the question mark after the file /etc/passwd? Is one also missing after /etc/group? The shell prompt is contained in the $PS1 variable. This isn't appearing on my screen properly. It's missing some quotes. This is also "missing" some quotes. It is not "right" yet. This is also "missing" 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. *** The entire line of text on each line must be made into exactly *one* argument to "echo". You can check your success by temporarily substituting the argv program from the Class Notes for the "echo" command. (You have to put the argv.sh program into the current directory under the name "argv.sh" and make it executable. Read the test.sh file for details on using this program. Remember to return the script to using only "echo" after your testing.) You'll know you got most of it right when you see this wc and sum output: $ ./test.sh | wc 8 77 456 $ ./test.sh | sum 15080 1 If your 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 hide *all* the blanks and special characters from the shell on each of the lines. C3. Run the script and redirect the output into file assignment09/testout.txt Part D - Linking exercise ========================= D1. Create an empty file assignment09/ln/abcd0001.txt, where the text abcd0001 is replaced by your *own* eight-character userid in the file name. NOTE: The sub-directory name is "ln", not "1n". D2. For every unique character in your own userid create a sub-directory under "ln" with that single-character name and hard link the file from the previous step into that sub-directory. Keep the same file name for each link. Use hard links, not symbolic links. For example, the userid "abca0151" would result in six unique subdirectory names under "ln" - one for each of the unique characters "a", "b", "c", "0", "1", "5" - and that user would hard link the original file name abca0151.txt into each of those six new subdirectories, creating six additional names for the same file. Do this for your *own* userid, which means you may have more or fewer subdirectories, depending on the letters and digits in your own userid. Keep the same file name for each hard link. Check the link counts on everything to make sure that you have created links to the same file and not made copies of the file. Use hard links, not symbolic links. D3. For every lower-case letter directory name you created, create a symbolic link that is its upper-case equivalent. If you created directory "a", then create symlink "A" that points to "a" so that both "ls a" and "ls A" give identical results. (You must use symbolic links, because you cannot make hard links to directories.) D4. In every file you have just created, enter the following information, one name per line: Enter the names of the three common file commands that are "directory only" commands that require permission on the directory inode to work properly, and that do *not* require permissions on the file inode to work. The answer is three lines, one command name per line. (See your in-class notes for Week 8, or see Worksheet 9, Part 1, Exercise 4.) The right answer has this format (three lines; three words; nine characters): $ wc abcd0001.txt 3 3 9 abcd0001.txt Again, the text "abcd0001" must be *your own* userid, in all cases. Hint: All the file names you created in this Part are links to the same file. Part Z - Check your work and submit =================================== Z1. There is a program named assignment09check in the Source Directory on the CLS. Create a symbolic link to this program in your account, named "assignment09/check". (Note: You can create a link to this executable program but you do not have permission to read the file.) Z2. Execute the above "check" program using its symbolic link. (Review the Class Notes on "Shell search PATH - finding and running commands" if necessary.) 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. When you like what you see on your screen, redirect the output into file assignment09/assignment09.txt so that you can then upload it to Blackboard as part of this assignment. Z3. Transfer the above assignment09.txt file from the CLS to your local computer and verify its contents. (No empty files, please!) Z4. Submit the assignment09.txt file with the exact name before the due date. Z5. Your instructor will mark the assignment09 directory in your CLS account after the due date. Leave everything there on the CLS. Do not delete anything until after the term is over. 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/