You will be using your favorite distribution of Linux for this lab. You will be creating and editing scripts in the Linux terminal window. Remember that you can bring up a web browser in your Linux distribution and access IvyLearn from there in order to attach your files to this assignment.
The attached document has the instructions for the lab. There are 3 exercises in the lab. The best way to do this assignment is to also bring up the PowerPoint presentation from the required reading on the M06 - Part 1: Learning Activities. As you step through that presentation, you will be prompted for each of the lab exercises. The presentation covers information that will be useful for you to complete the lab.
You will be attaching the lab document as well as 14 script files (including the "practice" ones you do as part of the PowerPoint presentation. The second file is a zip file that contains data files that are referenced in the lab instructions.
C5 MS Word Template Accessible SECURE SCRIPTING ADVANCED CONTROL LAB: FILE SYSTEM SCANNER This lab walks you through building a simple file system scanner. The scanner will be able to do three things. First, it will generate a list of files and file attributes, including a checksum of each file’s contents. Second, it can compare the files and file attributes of the files in the directory with that list. Third, it can delete that list. For this lab you will need the five files in the subdirectory “sample”. Please do not change anything in that directory — one of the tests you need to run depends on those files being unchanged. · abc xyz · abcde · demofor · demofor2 · demofor3 Lab exercise 1 This exercise starts you off. You do not need to write any scripts until Part D. First, list the attributes of the files in the directory “sample”, one per line. A. When you execute the command ls with the –l option, which of the desired attributes are printed? B. What does the command sha512sum print? C. How would you cause both outputs to be printed on the same line? D. Write a shell script that uses a for loop to list the attributes of the files in the directory “sample”, one per line. Call this script “scan1.sh”. Run your script. You should get information for six files, including the one you wrote. The checksums of the files “abcde” and “demofor.sh” are: da39a3ee5e6b4b0d3255bfef95601890afd80709 abcde 031b3606cf69ac7144a6fc47e9495d690b669084 demofor.sh Lab Exercise 2 You are now going to modify the script you wrote for Lab Exercise 1D to see if a master file exists and, if it doesn’t, create one. Then, in the loop, you will ignore any non-regular files and the master file. A. At the beginning of the script, add a line that defines a variable called MASTER, and give it the initial value “MasterList”. Call this script “scan2a.sh”. When you are done, save a copy because you will use this in Lab Exercise 3. B. After the variable definition but before your loop, test to see if the file named by the value of the variable MASTER exists. If so, print the message that the file “exists; please delete it” and exit, giving exit status code 1. If not, create it. Call this script “scan2b.sh”. C. In the for loop, before you print the file attributes, check to see if the file being examined is either a regular file or the MasterList file. If it is neither, immediately go to the next file (that is, do not get the file attributes). Call this script “scan2c.sh”. D. Modify your script so that the attributes are stored in the file named by the value of the variable MASTER. Call this script “scan2d.sh”. E. Finally, if everything works, have the script exit with an exit status code of 0. Call this script “scan2e.sh”. Run your script. There should be no output. Then look for a file called MasterList and compare its contents to what you got for the output of script1.sh. The outputs for the files abc xyz, abcde, demo.for.sh, demofor2.sh, and demofor3sh should be the same. The other files that are present should all be ones you created or put there. Lab Exercise 3 This exercise uses the copy of the script you saved after completing Lab Exercise 2A. We will be modifying it in a way similar to the rest of Lab Exercise 2. A. At the beginning of the script, add a line that defines a variable called TMP, and give it the initial value “/tmp/$$”. Then add another line that creates the file named by the value of TMP. Call this script “scan3a.sh”. What is the actual name of the file created? B. In the for loop, before you print the file attributes, check to see if the file being examined is the file named by the value of TMP, and if so, immediately go to the next file (that is, do not get the file attributes). Call this script “scan3b.sh”. C. Modify your script so that the attributes are stored in the file named by the value of the variable TMP. Call this script “scan3c.sh”. D. After the loop, print the message “Changed files:”, and then compare the contents of the files named by TMP and MASTER. Use diff to generate the comparison. Call this script “scan3d.sh”. What happens if the file named by the value of MASTER does not exist? E. Before the loop, check that the master file (the file named by the value of MASTER) exists. If it does not, print an error message saying “Master file does not exist; please generate it” and exit with an exit status code of 1. Call this script “scan3e.sh”. F. Conclude by using the command rm to delete the file named by the value of TMP after the comparison in Part D. Again, have the script exit with an exit status code of 0. Call this script “scan3f.sh”. When you test this script, the MasterList file must already exist. If it does not, execute the script you wrote in Lab Exercise 2. You should get at least one line for the file MasterList. You will also get other lines corresponding to the scripts you wrote. As long as you get the line for MasterList, you’re doing it right. Also, from the command interpreter, check the exit code. Immediately after you execute your script, type echo $? This prints the exit status code of the command that finished most recently. That command is your script. So you should see 0. Page | 1 This document is licensed with a Creative Commons Attribution 4.0 International License ©2017 Catalyzing Computing and Cybersecurity in Community Colleges (C5). Page | 6 This document is licensed with a Creative Commons Attribution 4.0 International License ©2017 Catalyzing Computing and Cybersecurity in Community Colleges (C5).