======================================= DAT2330 Test Three B - Unix - Questions ======================================= -IAN! idallen@ncf.ca You will need to be running Floppix with networking to do this test. You must have network access to use telnet and ftp to reach the machines mentioned in this test. Your directory test_three is where you must put your scripts and your script output if you want the instructor to mark them. This directory will be created by your instructor before you start your test. Your scripts do not have to create this directory; you may assume it exists any time a script specification requires you to use it. Only scripts and output found under directory test_three on the Test Machine will be marked. Only correctly-spelled script and file names will be marked. Your scripts must start with a valid Script Header, as given in class and in the Week 7 notes. You do not have to detect or handle errors in the scripts you write on this test. Error handling will be covered in Chapter 11. For example, your script does not need to check to see if a file or directory already exists before it tries to make one. Many of the scripts you write during this test will not run with­ out errors if you run them twice; because, the scripts will have created files and/or directories and a second attempt to re-cre­ ate the same files and/or directories may generate error mes­ sages. Make sure you clean out the results of one script run before you test your script a second time. Problem A - Marks: 14 On the Test Machine: Write an executable shell script named inputecho.sh that will do the following actions (in the order given below): 1. [Marks: 1] Display this exact sentence: My shell script is starting now. 2. [Marks: 2] Display this exact prompt for user input: A 2 word input: 3. [Marks: 2] Input one line from the user into two new shell variables. 4. [Marks: 3] Display the contents of the two shell variables in this exact format: Number one is: OOO Number two is: TTT where OOO is the contents of the first shell variable and TTT is the contents of the second shell variable. 5. [Marks: 2] Display this exact sentence: Your shell's using: KKK where KKK is the contents of the predefined shell keyword variable that contains your shell's search path. (Use the exact punctuation.) 6. [Marks: 2] Display this exact sentence: The name is SSS when you are here. where SSS is the contents of the predefined shell keyword variable that contains the name of your login shell. 7. [Marks: 1] Display the current date. 8. [Marks: 1] Display this exact sentence: My script is ending at the end. Problem B - Marks: 26 On the Test Machine: Write an executable shell script named commander.sh that will do the following actions (in the order given below): 1. [Marks: 2] Extract the first 50 lines of the file /etc/pjunk2 into a file named fiftyout.txt in the current directory. 2. [Marks: 2] Generate a long listing (showing permissions, owner, etc.) of all names in the /bin directory that end in the two characters sh into the file shells.txt in the current directory. 3. [Marks: 4] Display these two exact sentences: First is: 'FFF' Second is: 'SSS' where FFF is the text of the first positional command-line parameter to this script and SSS is the text of the second positional command-line parameter to this script. Use the exact output punctuation shown. 4. [Marks: 2] Make a sub-directory in the current directory, named using the text of the first command-line argument. (The first positional parameter contains the name of the new sub-directory that you must create.) 5. [Marks: 2] Move the existing file fiftyout.txt that you created earlier, into the sub-directory you just created in the previous step. 6. [Marks: 5] In the existing file fiftyout.txt that you already created, count the number of lines (only the lines) that contain the 4-character string (DAT and put the count into a new file named fcount.txt in the current directory. 7. [Marks: 2] Create a sub-sub-directory under the sub- directory you just created, named using the text of the second argument. (The second positional parameter contains the name of the new sub-sub-directory.) 8. [Marks: 2] Move the existing file fcount.txt that you created earlier, into the sub-sub-directory that you just created in the previous step. 9. [Marks: 5] Add group and other read permissions to the three files you have created in this script. (Each file is now in a different directory.) Problem C - Marks: 18 On the Test Machine: Write an executable shell script named namer.sh that will do the following actions (in the order given below): 1. [Marks: 2] Use a command to generate the host name of the current computer. Put the command output (the host name) into a shell variable. 2. [Marks: 2] Display this exact sentence: The computer is: XXX where XXX is the contents of the variable (the host name) from the previous step. 3. [Marks: 5] Select from the file /etc/hosts the one line that contains the host name of the current computer. Use the variable (the host name) from the previous step as your search pattern. Extract just the IP address (the first tab- delimited field) from that line. Put the output of this step (just the IP address) into a shell variable. 4. [Marks: 3] Use the two shell variables you just created and display this exact output: Address PPP belongs to machine NNN where PPP is the IP address and NNN is the host name of this computer. 5. [Marks: 2] Use a command to get the userid of the person running this script. Put the command output (the userid) into a shell variable. 6. [Marks: 2] Display this exact sentence: The person is: YYY where YYY is the contents of the shell variable (the userid) from the previous step. 7. [Marks: 2] Display the current date in ALL UPPER CASE LETTERS.