----------------------- Exercise #6 for DAT2330 due October 10 ----------------------- -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: 18h00 (6pm) Friday, October 10, 2003. The deliverables for this exercise are to be submitted online using the submission method described in the exercise description, below. No paper; no email; no FTP. Late-submission date: I will accept without penalty exercises that are submitted before 08h00 (8am) on Tuesday, October 14. After that late-submission date, the exercise is worth zero marks; but, it must still be completed and submitted successfully to earn credit in the course. Exercises submitted by the *due date* will be marked online and email sent to you after the late-submission date. A sample answer will be posted online after the late-submission date. Exercise Synopsis: This week you will use a "tar" format file archive to set up your home directory on a real Linux server located off-campus in my home. You will copy a tar archive, extract its contents, and assemble the contents into a JPEG picture file. (See the course discussion news group for how to see the contents of this picture file.) References and Readings: Running Linux: Chapter 4, Chapter 7, Lectures, online Notes. Where to work: Do your Unix command line work on the Course Linux Server located at SSH port 2330 on machine idallen.ca. (Backup link: alt.idallen.ca) You can find a copy of all the course Notes files on the Linux Server under directory: ~idallen/public_html/teaching/dat2330/03f/notes/ You can copy files from this directory to your own account. Exercise Details: 0. Did you read this week's notes yet? Read first; type second! 1. Use the tar command on ACADUNIX to build yourself a protected archive file under directory /tmp/ containing all the files in your home directory: Reference: Chapter 7 "Using tar" p.178-185 $ cd $ tar cvf /tmp/alleni99.tar . # "." means the current dir $ chmod go-rwx /tmp/alleni99.tar # or chmod 600 /tmp/alleni99.tar $ ls -l /tmp/alleni99.tar Replace "alleni99" with your own userid on ACADUNIX. (You must not try to build this archive of your home directory under your home directory! Why?) 2. Login to the Course Linux Server using SSH on port 2330. If you are on Knoppix, use this command line to connect: $ ssh -p 2330 -l abcd0001 idallen.ca Replace abcd0001 with your Algonquin userid. Your initial 8-character password for the Linux Server is the upper-case letter 'D' followed by the last 7 digits of your student number (not your PIN number). If you are on Windows, you must use the PuTTY program to connect using the SSH protocol and port 2330; see the week06notes.txt file for details. 3. Copy your tar file from ACADUNIX to the Course Linux Server and expand it. Execute these commands on the Course Linux Server: $ cd $ scp acadunix.algonquincollege.com:/tmp/alleni99.tar . $ ls -la $ tar xpvf alleni99.tar $ ls -la $ rm alleni99.tar You will see that the files from ACADUNIX have been restored to your new account on the Linux Server, with the same permissions. You can remove the tar file from both systems when you are finished. What does the -p option do for tar? (RTFM) See the file course_linux_server.txt under Notes for more details on how to copy files between ACADUNIX and the Linux Server. 4. On the Linux Server (NOT ACADUNIX), put your Assignment Label into a file named "newhome.txt". On the bottom of the file, after the label, append a recursive, long listing of your new account home directory on the Linux Server, with inode numbers, and showing *all* files. (RTFM to get the option that turns on recursion.) 5. Post a test article to the news group "algonquinc.test". Reference: Course home page "News&Discussion" button. Refresh your news reader ("Get messages") and read your test article. In a file named "posted.txt" on the Course Linux Server (NOT ACADUNIX), record the date and time that the test article was posted. 6. Post a second test article to algonquinc.test. Refresh your news reader ("Get messages") and read your test article. Now cancel this article ("Cancel", sometimes under the Edit button, sometimes under the right-click mouse menu). 7. Read the course announcements news group. 8. Read the course discussion news group. Please post your questions about general course content to this group, so that everyone can see the question and the answer. 9. Part II - to be announced. Watch for the final part of this exercise to be posted in the course announcement news group. ------- Part II (Updated 4pm Friday October 3) ------- 10. Create a new, empty directory somewhere in your account on the Course Linux Server (NOT ON ACADUNIX). Make this empty directory your current directory. All output should be into this new directory. 11. Under the course notes directory is a hidden file named ".exercise06.tar". (As stated above under "Where to work", a copy of the course notes directory is available on the Course Linux Server.) Copy this hidden file into your new empty directory. (You might want to give the copy a name in your directory that isn't hidden, e.g. "my.tar".) 12. Verify that you copied the tar file correctly: $ wc my.tar 232 2852 870400 my.tar 12. Expand the copied tar archive into the current (empty) directory. The archive contains three files. After you have expanded the tar archive, delete it. You will now have only three files in your directory. (Make sure you have only three files!) You should see this: $ ls | wc 3 3 18 13. Use a Unix command to determine what kind of information is in each of the three files from the tar archive. (HINT: The command that does this is in the top half of your list of commands from a previous exercise. Do not use "cat" or "less" on these files!) If any of the three files is itself a tar archive, expand that tar archive file and delete the tar archive file after you have expanded it. Remember to delete the tar file after you have expanded it. 14. You will now have 816 file names in the current directory, and 815 of the names will start with the letter "x": $ ls | wc 816 816 3752 $ ls x* | wc 815 815 3746 (How would you see a list of names that do *not* contain the letter "x"? HINT: use a pipe to a command that selects lines based on patterns.) 15. Concatenate together into a single new output file these input files: a) the one file whose name does not start with the letter "x" (this file will be one of the original three files) b) the 815 files whose names do start with the letter "x" (these "x" files came from inside the other two tar archives) Concatenate all 816 files together, in order, into one output file named "tux.jpg". (This can be done with one Unix command line using a simple GLOB pattern to match the 815 file names and redirection to create the new output file. Make sure the GLOB pattern does not match the name of the output file!) You may find you have to adjust the permissions on many of the input files so that you can read them and concatenate them. Your output file will contain the concatenated contents of 816 files. 16. Verify the output file size and checksum of your new tux.jpg file: $ wc tux.jpg 232 1215 89204 tux.jpg $ sum tux.jpg 17449 88 17. Remove the 816 files, leaving only tux.jpg in the current directory. (Use the same GLOB pattern you used to create the tux.jpg file.) 18. Move tux.jpg out of the current directory into the parent directory. The current directory will now be empty again. Is it empty? 19. Write an executable shell script named "decode.sh" to do the above steps. Build this script ONE LINE AT A TIME and test it after each line. You will not be able to make it work if you write a dozen lines and then try to debug it. Put your updated Assignment Label at the top of the script, below the usual "#!/bin/sh -u" line that must start all shell scripts. After the Assignment Label, set the search PATH for the script to be the usual directories "/bin" and "/usr/bin". (You did this last week for the listbin.sh script.) Always set the search path in your scripts! Your script must do the same steps you did, above: a) make a new, empty directory and make it the current directory b) copy the hidden exercise tar file to the current directory c) run wc on the copy d) expand the tar file and delete it e) run ls into wc to show only three files remain f) expand the two further tar archives and delete them g) run ls into wc to show that there are now 816 files h) run "ls x*" into wc to show that there are 815 files i) fix the permissions on all files to make them readable j) concatenate together the 816 files into "tux.jpg" k) run both wc and sum to show that tux.jpg is the correct size l) remove the 816 files m) move tux.jpg up to the parent directory Note: The above list of steps is a summary of the things the script needs to do. It is not a count of how many lines of commands you will need to do the given actions. Some of the above steps require more than one Unix command. (Do not place multiple Unix commands on the same line inside a shell script. Use one line per command.) Your script will have six lines of output from the above commands: $ ./decode.sh 232 2852 870400 my.tar 3 3 18 816 816 3752 815 815 3746 232 1215 89204 tux.jpg 17449 88 After the script runs, the directory it creates will be empty and the file tux.jpg will be in the current directory. 20. Add comments and blank lines before each group of commands in the script, explaining *why* you are doing these things in the script. (What is the purpose of the group of commands? Why is it there?) Scripts without comments are unsatisfactory; they are worth zero marks. You must submit comments with your scripts. One comment may serve to explain several Unix commands; you do not need a comment in front of every single command line in the script. 21. Submit the three files newhome.txt, posted.txt, and decode.sh for marking on the Linux Course Server as Exercise 06. The submit program is named "datsubmit" and is in your standard search path on the Course Linux Server (you won't find it under ~alleni/bin/). The "datsubmit" command on the Linux Server takes the same arguments as the "submit" program on ACADUNIX. Use 06 as the first argument (submission number) for Exercise 6, followed by three pathnames. Use the Course Linux Server. Do not work on ACADUNIX.