----------------------- Exercise #05 for CST8129 due February 14, 2006 ----------------------- -Ian! D. Allen - idallen@idallen.ca Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) Global weight: 2% of your total mark this term Due date: 23h59 Tuesday February 14, 2006 Late-submission date: I will accept without penalty exercises that are submitted late but before 10h00 on Thursday, February 16. After that late-submission date, the exercise is worth zero marks. Exercises submitted by the *due date* will be marked online and your marks will be sent to you by email after the late-submission date. Where to work, location of the course notes on the Course Linux Server, exercise preparation: See exercise01.txt for all the above details. NOTE: For full marks, keep your lines shorter than 80 columns in this course! Keep your terminal window set to 80 columns. The VIM editor will automatically wrap most lines as you type them if you enter "set wrapmargin=5" in your $HOME/.vimrc file. ------------------------- Part I - Exercise Details ------------------------- Synopsis: Write a shell script to decode an image file from pieces. A. Create an executable shell script file named "exercise05script.sh" following the model used in Exercise #3, Part II, steps 1-5. B. Copy the README.txt file from under directory ~idallen/image/ into the "Purpose" section of your script file. Edit the text to remove inappropriate lines and make the text match the actions of your shell script. (To avoid plagiarism charges, remember to credit the source of the material you copied!) Put octothorpe comment characters ("#") in front of all the lines to make them comments. (Easy Way Hint: The special character ^ matches the start of a line in a VIM :s/^// substitute command.) Your file will now be in these sections, in this exact order: - #! shell interpreter line (comment) - Syntax (comment - no arguments) - Purpose (comments from edited version of README.txt) - your Assignment Label (comments) - set PATH, LC_COLLATE, LC_LANG, and umask Execute the script file and make sure there are no errors and no output. (You only added comment lines - the file should produce no output.) Add commands to your script file, one by one, that will do the steps below, in order. You must make sure each command works at the command line before you copy it into the the script file and then test it by executing the file. (Easy Way Hint: Work with two or three shell windows open.) 0. Read the whole exercise through first before you start coding. 1. Remove recursively (and silently) any directory named "image5". (Hint: Find an option to have the command ignore nonexistent files so that you don't get an error message if the directory isn't there.) 2. Create a new directory named "image5" in the current directory. 3. Change directories to make image5 the current directory. 4. Show on the screen the full absolute pathname of the current directory. 5. Copy all the image fragment files from directory ~idallen/image/ (on the Linux Server) into the current directory. (You have to copy the files to your account because you cannot rename them where they are, in my account.) (Hint: Use a shell GLOB pattern to match all the names you want to copy. The destination pathname should be the current directory.) 6. Use commands to rename the few damaged files to have their correct names. You will have to do some detective work to figure out which file names need to be renamed, and what the names should be. You will need to use quotes to hide special characters from the shell. Put the renaming commands into your script. (Hint: Five files need to be renamed.) At this point you should have 179 image fragment file names in the current directory, all starting with the same file name prefix. 7. Concatenate all 179 fragment files into one file named image.jpg (The shell will sort GLOB pattern match file names alphabetically.) 8. Remove all the file fragments, and any other files in the current directory, leaving only the one single image.jpg file. (Rememer to remove this README file too.) 9. Use commands to display the permissions, size, and checksum of the image.jpg file. (The size and checksum must match the numbers given in the README.txt file.) 10. Above each of the lines in your working script, add a line that echoes the question number. Under that echo line, add a one-line (less than 80 characters!) comment explaining in your own words what the command line that follows the comment does. Each answer will look similar to this: echo "--- Question 1" # display a count of the logged in users on this machine who | wc In your script source, leave one blank line between each question you answer, to make the script readable. (You may also echo blank lines to the screen to separate the output sections, if you wish.) Scripts without comments in your own words will not be marked. This script that re-assembles the image fragments will have about 16 executable (non-comment) shell command lines in it (including the four executable lines up to and including the "umask" statement). Your answer may differ slightly. Execute your file in your home directory and make sure there are no errors: $ ./exercise05script.sh You can use the "xli" or "display" commands to display the image.jpg file under Linux, or you can copy it to another machine for display. --------------------- Part II - Future Work --------------------- For upcoming exercises you will need to run "script" sessions to use "nc" connect to servers, following the models used in the course notes: http_session.txt nntp_session.txt smtp_session.txt Before you leave the lab today, make sure you can follow each of the sample sessions in the above file and get similar results. Submission ---------- NOTE: For full marks, keep your lines shorter than 80 columns in this course! Keep your terminal window set to 80 columns. The VIM editor will automatically wrap most lines as you type them if you enter "set wrapmargin=5" in your $HOME/.vimrc file. NOTE: Make sure your exercise05script.sh file follows the format from exercise03script.sh Part II (up to the umask 022 line). Class Notes reference: netsubmit.txt - Using the netsubmit command Submit the output and the finished and labelled file for marking as Exercise 05 on the Course Linux Server, using the following netsubmit command line: $ netsubmit 05 exercise05script.sh $ netsubmit -list Scripts without comments in your own words will not be marked.