----------------------- Exercise #4 for CST8129 due October 5, 2005 ----------------------- -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: 3% of your total mark this term Due date: Before the end of your Lab period on Wednesday, October 5. The online deliverables for this exercise are to be submitted online via the T127 Linux Lab using the submit method described in the exercise description, below. No paper; no email; no FTP. Late-submission date: I will accept without penalty online exercises that are submitted late but before 09h00 (9am) on Friday, October 7. 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. This exercise is due before the end of your Lab period on October 5. Exercise Synopsis: Marks: 3% Write a shell script to decode an image file from pieces. Where to work: Do your Unix command line work on any WT127 workstation. (You may login to the workstation remotely.) The files you work on will remain in your account after you log off. Do not erase your files after submission; always keep a spare copy of your exercises. WARNING: Do not attempt this exercise on a Windows machine - the text file format is different. You must connect to and work on Unix/Linux. Note that you may connect to a lab workstation *from* a Windows machine (using PuTTY); however, you may not use the Windows machine itself to do your work. Use the vim editor on the Linux machine. Location of the course notes on the Lab workstations: You can find a copy of all the course Notes files on any Lab workstation under directory: ~alleni/public_html/teaching/cst8129/05f/notes/ You can copy files from this directory to your own account for modification or study, if you like. (To avoid plagiarism charges, you must credit any material that you copy and submit unchanged as your own work.) Location of the textbook CDROM files on the Lab workstations: The CDROM files for the Quigley textbook are available in the WT127 Lab under the directory: /home/cst8129/ Exercise Preparation: A. Know where to find an online copy of all the course Notes on the Lab workstations. (See above.) You can get a copy of this exercise from the course notes. B. Complete the online Course Notes readings. Any questions? See me in a lab or post questions to the Discussion news group (on the top left of the Course Home Page). --------------------------------------------- Exercise Details (in the T127 Linux Lab) --------------------------------------------- 1. Create a file named "exercise04script.sh" with these four lines in it: #!/bin/sh -u PATH=/bin:/usr/bin ; export PATH LC_COLLATE=C ; export LC_COLLATE umask 022 The lines must be at the left margin, with no leading or trailing blanks or blank lines. The word count and checksum of the resulting file will be: $ wc exercise04script.sh 4 12 89 exercise04script.sh $ sum exercise04script.sh 35197 1 2. Make the file executable: chmod +x exercise04script.sh Make sure the file executes without errors: ./exercise04script.sh (There will be no output from the file yet.) 3. Add your Assignment Label to the file as comment lines, below the /bin/sh line and above the PATH line. Make sure the first line of the script remains the shell interpreter line (as given above). 4. Copy the README.txt file from under directory ~alleni/image/ into the end of your script file, below your Label. Put octothorpe comment characters ("#") in front of all the lines. 5. Copy the block of questions below into the end of the script file and add octothorpe comment characters ("#") in front of all the lines. Your file will now be in these sections, in this exact order: - shell interpreter line (comment) - Assignment Label (comments) - set PATH, LC_COLLATE, and umask - README.txt (comments) - Questions 6-14 (comments) 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.) Under each numbered question 6-14 below, add commands, 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. (Hint: Work with two or three shell windows open.) 6. Remove recursively any directory named "image4". (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.) 7. Create a new directory named "image4" in the current directory. 8. Change directories to make image4 the current directory. 9. Show on the screen the full pathname of the current directory. 10. Copy all the image fragment files from directory ~alleni/image/ (in the Linux Lab, T127) 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.) 11. 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. (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. 12. Concatenate all 179 fragment files into one file named image.jpg (The shell will sort GLOB pattern match file names alphabetically.) 13. Remove all the file fragments, and any other files in the current directory, leaving only the one single image.jpg file. 14. 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.) This script that re-assembles the fragments will have about 16 executable (non-comment) shell command lines in it. Your answer may differ slightly. Execute your file and make sure there are no errors: $ ./exercise04script.sh You can use the "display" command to display the image.jpg file under Linux. Submission ---------- Submit the finished and labelled exercise04script.sh file for marking using the following Linux command line: $ ~alleni/bin/copy exercise04script.sh This program will copy the selected file to me for marking. You can copy the file more than once. Only the most recent copy will be marked. This exercise is due at the end of your lab period today. P.S. Did you spell all the label fields and file names correctly?