This assignment continues the work you did in the previous assignment, but is optional. You will continue working through the presentation and the lab document as before, but this time you will have 8 scripts to submit. You will be attaching the lab document and the script files.Lab Document:
C5 MS Word Template Accessible SECURE SCRIPTING ADVANCED CONTROL LAB EXERCISE 4 Now combine the scripts you wrote for Lab Exercises 2 and 3. Your script, which you are to call “scan4.sh”, should define the variables TMP and MASTER, then do the parts of Lab Exercises 2 and 3 in the following order: 2A, 3A, 3B, 2C, 3C, 3D, 3E, 2E Do not include Exercises 2B or 2D in this script. Then, before the line you wrote for Exercise 3D, have the script print “Changed files:” and add the following on the same line as the command you wrote for Exercise 3D: | grep '^\(<\|>\)' | awk '{ print $NF }' | sort | uniq (The vertical bars “|” and quotation marks are critical.) This addition will change the output of your diff command so that the files that have been changed have their names listed in alphabetical order. It will make the output clearer for the user. Run your script twice to test it. First, just run it. The list of changed files should have only the ones you have written and left in the directory. Then change the time of last modification of the file “abcde” by typing touch abcde Now rerun the script. The list should be the same as before but with the addition of “abcde”. LAB EXERCISE 5 Now you will modify the script from Lab Exercise 4 to handle two options. First we will handle the option –g, which creates the master file, then -d, which deletes the master file. If the script is called with no arguments, it will generate a list of files the attributes or contents of which have changed since the master list was created. Page | 1 This document is licensed with a Creative Commons Attribution 4.0 International License ©2017 Catalyzing Computing and Cybersecurity in Community Colleges (C5). http://www.c5colleges.org/ https://creativecommons.org/licenses/by/4.0/ https://creativecommons.org/licenses/by/4.0/ For the –g option: A. Create a variable called GENMASTER and, at the beginning of the script, set it to “no”. Call this script “scan5a.sh”. B. If the –g option is given, set GENMASTER to “yes”. Call this script “scan5b.sh”. What happens if you give some other argument or option, like “-m”? C. After the argument processing loop, check to see whether GENMASTER is “yes”. If it is, do what you do in the script that was the answer to Lab Exercise 2; you can just copy it into this script if you like, but if you do, don’t copy the line setting the variable MASTER. Then exit with an exit status code of 0. If it is “no”, do what you do in the script that was the answer to Lab Exercise 3; again, you can just copy it into this script if you like, but don’t copy the lines setting the variables MASTER and TMP. Exit with an exit status code of 0. Call this script “scan5c.sh”. Test your script by running it in the sample directory. First, do not give the –g option; you should get a list of files that have changed, most likely including abcde (from Lab Exercise 4). Then run it again giving the –g option. You should get the error message saying the master file exists, please delete it. For the –d option: D. Create a variable called DELMASTER and, at the beginning of the script, set it to “no”. Call this script “scan5d.sh”. E. If the –d option is given, set DELMASTER to “yes”. If any command-line option (or argument) other than –d or –g is given, print the error message “Unknown option” followed by the option, and exit with an exit status code of 1. Call this script “scan5e.sh”. F. Before you check the value of the variable GENMASTER, if the value of DELMASTER is “yes”, check that the master file exists. If it does, delete the master file and exit with an exit status code of 0. If it does not, print “Master file does not exist; please generate it” and exit with a status code of 1. Otherwise, if the –d option is not given, continue. Call this script “scan5f.sh”. Test your script by running it in the sample directory. First, do not give the –d option; you should get a list of files that have changed, most likely including abcde (from Lab Exercise 4). Then run it again giving the –d option. You should get the error message saying the master file exists, please delete it. Page | 2 This document is licensed with a Creative Commons Attribution 4.0 International License ©2017 Catalyzing Computing and Cybersecurity in Community Colleges (C5). http://www.c5colleges.org/ https://creativecommons.org/licenses/by/4.0/ https://creativecommons.org/licenses/by/4.0/ Finally, do some sanity checking. It makes no sense to give both the –d and –g options, so we need to give an error message if both are set. G. Right after you process the arguments (options), check the values of DELMASTER and GENMASTER. If both DELMASTER and GENMASTER are “yes”, print the error message “Only one of –d, -g allowed” and exit with an exit status code of 1. Call this script “scan5g.sh”. Page | 3 This document is licensed with a Creative Commons Attribution 4.0 International License ©2017 Catalyzing Computing and Cybersecurity in Community Colleges (C5). http://www.c5colleges.org/ https://creativecommons.org/licenses/by/4.0/ https://creativecommons.org/licenses/by/4.0/ Lab Exercise 4 Lab Exercise 5\|>