CIS 90 - Spring 2014 - TEST 2 - 30 points HONOR CODE: This test is open book, open notes, and open computer. HOWEVER, you must work alone. You may not discuss the test questions or answers with others during the test. You may not ask or receive assistance from anyone other than the instructor when doing this test. Likewise you may not give any assistance to anyone taking the test. NAME: --> please replace this text with your name <-- INSTRUCTIONS: Download or copy and paste this page from your web browser into a text file on your computer. Don't use a word processor like MS Word! Instead use a text editor like Notepad (Windows) or TextWrangler (Mac) to add your answers to the questions below. Everyone should submit their test (completed or not) by the end of class. If you need extra time, you can submit again by no later than 11:59PM. Only the last submittal will be graded. This test should be completed using the Sun-Hwa-II system only. Log into Opus first then ssh into Sun-Hwa-II. For questions with a *** you will be expected to do the requested operation in addition to answering the question. When grading, the instructor will check your answers and verify the operations were successfully completed. For questions not marked with a *** it may still be helpful to use Sun-Hwa-II to check your answers. [ ]'s are used to indicate the directory you should be in to do an operation. This will be your starting point for any relative pathnames. Please KEEP YOUR ANSWERS TO A SINGLE LINE ONLY and preserve the tags, e.g. "A1)", "A2)", etc. used to label the answers. Note to instructor: - Create student and extra accounts (Sun-Hwa-II) - Run setup-test2 T2 (Sun-Hwa-II) - Remove /etc/nologin (Sun-Hwa-II) [ ------------------------------------------------------------ ] [ Troubleshooting (1 point each) ] [ ------------------------------------------------------------ ] Instructions: Login to Sun-Hwa-II from Opus using just: ssh sun-hwa-ii Q1) *** Before doing anything else run the flag command. What is the output from the flag command? A1) Q2) There is some serious trouble with your Sun-Hwa-II account that you need to troubleshoot and repair. Many of the commands we learned, such as ls and cat, no longer work. What EXACTLY is the problem? Be specific as to why this problem is occurring. A2) Q3) *** Once you have identified the problem, what single command will resolve the issue so all the commands work again? A3) Note: To confirm your fix run ./checkfix in your home directory. If you get stuck and can't fix this problem then ask the instructor for the solution and give up the points for Q2 and Q3. Q4) Benji (user simben90) needs your help. He has a directory named games/ containing several files. He wants to share these files (e.g. chase and gopher) with his CIS 90 classmates but not with any of the Lost characters (like John Locke or Mr. Eko). On each of these files he has set read permissions for the group and no permissions for others: [simben90@sun-hwa-ii ~]$ ls -l games total 24 -rw-r-----. 1 simben90 T2 10 Apr 6 17:22 chase -rw-r-----. 1 simben90 T2 10 Apr 6 17:22 fetch -rw-r-----. 1 simben90 T2 10 Apr 6 17:22 glove -rw-r-----. 1 simben90 T2 10 Apr 6 17:22 gopher -rw-r-----. 1 simben90 T2 10 Apr 6 17:22 puppet -rw-r-----. 1 simben90 T2 10 Apr 6 17:22 sock [simben90@sun-hwa-ii ~]$ However when his friend Homer, who is also a CIS 90 classmate, tries to read one of these files he gets this error: [milhom90@sun-hwa-ii ~]$ cat ~simben90/games/gopher cat: /home/cis90/simben/games/gopher: Permission denied What single command can Benji use from his home directory to fix the problem so any CIS 90 student (but none of the Lost characters) can read these files (feel free to explore Benji's directories or use the generic cis90 account for testing purposes) A4) [ ------------------------------------------------------------ ] [ Managing files (1 point each) ] [ ------------------------------------------------------------ ] Instructions: Explore the VAULT/ and Islands/ directories in your home directory. In the VAULT directory is another directory named things/. In things/ you will see some directories named after oceans and some files named after islands. The next few questions guide you through reorganizing your home directory. Q5) *** [From your home directory] What single command "unlocks" your VAULT/ directory so you and NO ONE ELSE can examine its contents? A5) Q6) *** [From the Islands/ directory] What single command will move (not COPY) the CONTENTS of the things/ directory (but not the things/ directory itself) to the Islands/ directory? (Be careful to not change the contents of the files which contain custom information) A6) Q7) *** [From the Islands/ directory] What single command MOVES the Maldives, Seychelles and Zanzibar files into the Indian/ directory? A7) Q8) *** [From the Islands/ directory] What single command MOVES the Atlantis, Treasure_Island and Isla_Nublar files into the Fictional/ directory? A8) Q9) *** [From the Islands/ directory] What single command copies the Antarctic/ directory and the three island files in it from the TOP OF THE FILE TREE to the Islands/ directory? A9) Q10) *** [From your home directory] What single command removes the things/ directory from VAULT? A10) When finished you can compare your work with Benji's below. They should match exactly. If you need to start over you can use ./restore to put your home directory back to the original state. [simben90@sun-hwa-ii ~]$ tree VAULT/ VAULT/ 0 directories, 0 files [simben90@sun-hwa-ii ~]$ tree Islands/ Islands/ +-- Antarctic ¦   +-- Balleny_Islands ¦   +-- Heard_Island ¦   +-- Scott_Island +-- Fictional ¦   +-- Atlantis ¦   +-- Isla_Nublar ¦   +-- Treasure_Island +-- Indian +-- Maldives +-- Seychelles +-- Zanzibar 3 directories, 9 files [simben90@sun-hwa-ii ~]$ [ ------------------------------------------------------------ ] [ Permissions (1 point each) ] [ ------------------------------------------------------------ ] Instructions: Review the contents of the readme file in your home directory to find the permissions to use in this step. Q11) *** [From your home directory] What single command changes the permissions on just your Islands/ directory and its three sub-directories (Antarctic/, Fictional/, Indian/) to what is specified in your readme file? (your command should not change the permissions of any of the regular island files in those directories) A11) Q12) *** [From your home directory] What single command changes the permissions on all your regular island files (e.g. Atlantis, Maldives, ..., etc.) to what is specified in your readme file? (your command should not change the permissions of any of the directories) A12) Q13) *** What single command would automatically strip the following permissions from future files and directories when they are created? (test your answer on Sun-Hwa-II) For user strip write and execute permissions For group strip all permissions For others strip read permission only A13) Q14) What are the permissions, in NUMERIC format, on the hidden Rumpelstiltskin file in your home directory? A14) Q15) *** Set the umask setting to 777 and copy the hidden tar file in your home directory to backup.tar. What are the permissions in numeric format on backup.tar? A15) [ ------------------------------------------------------------ ] [ Finding things (1 point each) ] [ ------------------------------------------------------------ ] Instructions: Restore your umask settings back to 022 again. DON'T FORGET TO DO THIS! You can also log out and back in again and redo the troubleshooting. Q16) There is a file in the /etc directory named passwd. This file has information on all user accounts including usernames, UIDs, first and last name, etc. What is the absolute pathname of this file? A16) Q17) *** [From your home directory] There is a large file full of cities in the /usr/share branch that belongs to Penny Widmore. Locate this file and examine it. Each line has several fields separated by ":" characters. The first line is the header which has the name of each field. What command could you use to create a SYMBOLIC link to this file in your home directory named cities? A17) Q18) *** [From your home directory] The huge cities file has random words in the last two fields of each line. Some of these random words are actually first and last names of CIS 90 students. Find your city by finding the line containing your first and last name. What single command, using your cities symbolic link as the argument, will locate your line? A18) Q19) The first field of the line with your name has your city. What city did you get? A19) Q20) *** Now search the /usr/share branch for a file named after your city. Create a HARD link to this file in your home directory named mycity. Add execute permissions to mycity and run it using ./mycity. What does mycity output when you run it? A20) Q21) *** Every CIS 90 student was assigned a different city file. The first, second and fourth lines of each city file are identical. Given that, what command can you use to find all the city files in the /usr/share branch? (your command must discard any permission error messages) A21) Q22) Who is the owner of your city file? A22) [ ------------------------------------------------------------ ] [ Input/Output (1 point each) ] [ ------------------------------------------------------------ ] Q23) *** [From your home directory] What pipeline command would do a spell check of all your island files in Island/ and mail them to yourself and rsimms (on Sun-Hwa-II) with a subject of "misspelled words"? A23) Q24) *** What command would both SHOW the value of your shell prompt variable and RECORD it in a file named PS1.bak? A24) Q25) *** What command would print a SORTED list of the FIRST names of all the CIS 90 students who have accounts on Sun-Hwa-II? A25) Q26) *** [From your home directory] There is a file named "expressions" containing some mathematical expressions to solve. Using only the bc command and redirection (no | or ; please) issue a single command that: a) inputs expressions to calculate from the file "expressions" b) APPENDS the calculated answers to /etc/cis90calcs c) writes (not appends) any error messages to a file named "errors" What single command does all this? A26) [ ------------------------------------------------------------ ] [ Six steps of the shell (1 point each) ] [ ------------------------------------------------------------ ] Q27) After issuing the following commands, how many lines would the file nums have and why? echo 5 > nums echo 4 > nums echo 3 >> nums echo 2 >> nums echo 1 >> nums A27) Q28) What would be the result of issuing the following commands and why? echo apple > fruit echo pear >> fruit echo peach >> fruit echo plum >> fruit echo strawberry >> fruit sort fruit > fruit A28) Q29) If Benji ran these commands on Sun-Hwa-II: PATH=/etc/.trouble/bin/T2/:/bin:/usr/bin/:/usr/local/bin:/home/cis90/simben/bin tty When the shell searches for the tty command above, which directory would the shell find it in? A29) Q30) On Sun-Hwa-II, what is the absolute pathname of the DIRECTORY containing the flag command? A30) [ ------------------------------------------------------------ ] [ Extra credit (1 point each) ] [ ------------------------------------------------------------ ] Q31) *** Write a pipeline command using only grep, xargs, cut and sort that would produce a sorted list of the country abbreviations found in the city files assigned to CIS 90 students for this test. The country codes are the two character codes like NO for Norway or FR for France. Suppress any permission errors. The output should match: AT AZ BG CA CN CZ DE ES ES FR FR FR FR GB GB GB GB IE IE IS IT NA NL NL NL NO PL US US US A31) Q32) *** What two commands would allow you to run checkfix and mycity, from anywhere, without having to put the "./" in front of them? (use the ; metacharacter to separate the two commands in your answer) A32) Q33) *** Create a directory named "tmp" in your home directory. Give it the EXACT same permissions as those found on the system /tmp directory. What are the FULL (4 digit) permissions on your tmp directory? A33) [ ------------------------------------------------------------ ] [ Submit this test ] [ ------------------------------------------------------------ ] When finished, leave your home directory intact. Each question above with a *** will be graded by looking at both your answer and by checking that the changes were correctly made. Copy and paste this completed test into a text-only email with NO attachments to: rsimms@oslab.cabrillo.edu @oslab.cabrillo.edu CONFIRM on Opus that your email was successfully sent and that your work is READABLE using the mail command.