========================== Problems for Test 4 - Unix ========================== -IAN! idallen@ncf.ca Preamble -------- 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. The test_four directory used in some of the scripts, below, is a sub-directory of your HOME directory on the Test Machine. This directory will be created by your instructor before you start your test. Your directory test_four is where you must put your scripts and your script output if you want the instructor to mark them. 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_four 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. Helpful block comments ahead of your code will assist the instructor in giving you marks even for code that doesn't quite work. --------------------- Problem A - Marks: 21 --------------------- On the Test Machine: Write an executable shell script named apple.sh that will do the following actions (in the order given below): 1. [Marks: 2] Expect exactly two command line arguments to this script. If there are not exactly two arguments, print a helpful error message and exit. 2. [Marks: 3] Test to make sure that each argument is the pathname of an existing file (not a directory). If this is not true, print a helpful error message and exit. 3. [Marks: 3] Test to make sure that each pathname is readable. If this is not true, print a helpful error message and exit. 4. [Marks: 3] Test to make sure that each pathname is not executable. If this is not true, print a helpful error message and exit. 5. [Marks: 3] Test to make sure that each pathname is not zero-size. If this is not true, print a helpful error message and exit. 6. [Marks: 2] If the files are identical in content (have no differences), exit silently with a good status. 7. [Marks: 5] If the files are different, print the fol­ lowing message on stdout: NNN: File 'XXX' and file 'YYY' are different. NNN: Number of lines of differences: ZZZ where NNN is the current name of this script, XXX is the name of the first file, YYY is the name of the sec­ ond file, and ZZZ is the count of the number of lines output by the diff command applied to the two files. -------------------- Problem B - Marks: 8 -------------------- On the Test Machine: Write an executable shell script named berry.sh that will do the following actions (in the order given below): 1. [Marks: 2] Expect one or more command line arguments to this script. If there are no arguments, print a help­ ful error message and exit. Loop for each command line argument: 2. [Marks: 4] Count the number of characters in the text of the command line argument. Display this message (using the given punctuation): Argument 'XXX' contains YYY characters. where XXX is the the text of the command line argument, and YYY is the count of characters in that argument. 3. [Marks: 2] If there are no characters in the argument, also output this message on stdout: The argument is empty. Loop until all command line arguments have been processed. Example: berry.sh "abc" should output a count of 3 for the count of three characters in the text string abc. --------------------- Problem C - Marks: 22 --------------------- On the Test Machine: Write an executable shell script named cherry.sh that will do the following actions (in the order given below): 1. [Marks: 2] The script must have exactly one command- line argument (a pathname). If this is not true, print a helpful error message and exit. 2. [Marks: 3] Make sure the pathname argument (the only argument) is the name of an existing, readable file (not a directory). If this is not true, print a help­ ful error message and exit. 3. [Marks: 4] Make sure the very last line of the file (the argument) is the line: END OF FILE If this is not true, print a helpful error message and exit. Include the incorrect last line you found as part of the error output. 4. [Marks: 1] Output File 'XXX' contains YYY lines. where XXX is the name of the file (the argument) and YYY is the number of lines in the file. 5. [Marks: 3] The script needs to input a text string. Prompt the user for a text string, read it (a text string), and echo it back to the user. 6. [Marks: 2] Output String 'XXX' appears on YYY lines. where XXX is the text string and YYY is the count of the number of lines on which it appears in the file (the argument). 7. [Marks: 4] Test to see if the count of lines containing the text string is less than the total number of lines in the file. If the count is less, extract all the lines from the file that do not contain the text string into a new file in the current directory named no_string_foundXXX.txt where XXX is replaced by the current process ID of the script. 8. [Marks: 1] If the count is less, remove all group and other permissions from this new file you just created. 9. [Marks: 1] If the count is less, show a long listing of this new file you just created. 10. [Marks: 1] If the count is less, rename the file you just created to have the name unfound.txt in the cur­ rent directory.