====================================== DAT2330 Test Four A - 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_four 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_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. Scripts without a valid header will be penalized. Scripts containing useful comments will earn bonus marks, to a maximum of five marks per script. Problem A - Marks: 50 On the Test Machine: Write an executable shell script named whodater.sh that will do the following actions (in the order given below): 1. [Marks: 6] Verify that there are exactly two command line arguments; otherwise, exit with an error message. (i.e. Exit if there are not two arguments.) 2. [Marks: 2] Put the first argument into a variable named mydir. 3. [Marks: 2] Put the second argument into a variable named myfile. 4. [Marks: 5] Verify that the path named by the mydir variable is a directory; otherwise, exit with an error message. (i.e. Exit if the path is not a directory.) 5. [Marks: 5] Verify that the path named by the mydir variable is writable; otherwise, exit with an error message. (i.e. Exit if the directory is not writable.) 6. [Marks: 5] Verify that the path named by the mydir variable is searchable; otherwise, exit with an error message. (i.e. Exit if the directory is not searchable.) 7. [Marks: 2] Put the file pathname $mydir/$myfile into a variable named newfile. (Do not create this file yet.) 8. [Marks: 5] Verify that the file named by the newfile variable is zero size or nonexistent; otherwise, exit with an error message. (i.e. Exit if non-empty.) 9. [Marks: 3] Put the current date into the file named by the newfile variable. Exit with a non-zero exit status if the command fails. 10. [Marks: 3] Put the pathname for a temporary file into a variable named tmp. Use the process ID of the current process in the pathname. The pathname of the temporary file should be under the /tmp directory. (Do not create the file yet.) 11. [Marks: 4] Put a sorted list of online users into the temporary file named by the tmp variable. Exit with a non- zero exit status if the command fails. 12. [Marks: 3] Append the contents of the temporary file (the list of online users) to the file that contains the date (created in a previous step). Exit with a non-zero exit status if the command fails. 13. [Marks: 3] Also append this exact sentence to the same file: The number of users is XXX. where XXX is the number of lines in the temporary file. 14. [Marks: 2] Remove the temporary file. Problem B - Marks: 58 On the Test Machine: Write an executable shell script named compiler.sh that will do the following actions (in the order given below): 1. [Marks: 6] Verify that there is zero or one command line argument; otherwise, exit with an error message. (i.e. Exit if there is more than one argument.) 2. [Marks: 7] If there are no command line arguments, prompt the user to enter the missing file name and read the name from standard input. Put the file name (either the command line argument or what the user entered from standard input) into the variable myprog for use in the rest of the script. 3. [Marks: 2] Display this exact sentence: You are processing file 'XXX'. where XXX is the contents of the myprog variable containing the file name that the user specified. Use the exact punctuation. 4. [Marks: 5] Verify that the path named by the myprog variable is a file; otherwise, exit with an error message. (i.e. Exit if the path is not a file.) 5. [Marks: 5] Verify that the file named by the myprog variable is readable; otherwise, exit with an error message. (i.e. Exit if the file is not readable.) 6. [Marks: 5] Verify that the file named by the myprog variable is not empty; otherwise, exit with an error message. (i.e. Exit if the file is empty.) 7. [Marks: 9] If the file named by the myprog variable contains the 7-character string cout << then compile the file using the C++ language compiler. Turn on all warnings during the compile. Name the compiled output program newcpp. Save any error or warning messages that may be generated on standard error by the C++ compiler into a file named warnings.out in the current directory. Save the exit status of the C++ compiler in a variable named cstatus. 8. [Marks: 9] If the file named by the myprog variable does not contain the 9-character string