----------------------- Exercise #4 for DAT2330 due September 24 ----------------------- -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: 12:00 noon Wednesday, September 24, 2003. The deliverables for this exercise are to be submitted online on ACADUNIX using the "submit" 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 10h00 (10am) on Friday, September 26. 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 create a more complex shell script. You will also make a list of Unix commands that will be useful in studying for the upcoming Midterm Test. References and Readings: Running Linux: Chapter 4, Lectures, online Notes. Where to work: Do your Unix command line work on the ACADUNIX computer. You can find a copy of all the Notes files on ACADUNIX under this directory: ~alleni/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. On ACADUNIX make another new, empty directory somewhere in your account. You may use any name you like. 2. Move into the new empty directory you just created. (i.e. Make the empty directory you just created your current working directory for this week's exercise.) 3. Verify that you are in the empty subdirectory you just created. Stay in this subdirectory. The outputs of your scripts and commands should create files in this new subdirectory (not in your home directory). 4. Copy the argv.sh.txt file from the Notes to the current directory. Rename it to be argv.sh and make sure it is executable. (Test it.) Use this script to verify how the shell handles command line arguments: $ ./argv.sh "how many "' arguments' are "there to " this '?' $ ./argv.sh /bin/[abc]*t $ ./argv.sh .* 5. Copy your last week's executable shell script into the current directory and name it: myscript04.sh Make sure the copy is also executable. 6. Update the Assignment Label in file myscript04.sh for this week and delete everything below the label. (Remove last week's four commented commands and their associated comments.) 7. Below the Label in myscript04.sh put new shell command lines that will have your script do the following seven actions. I recommend adding one action at a time and debugging it before you add the next one. The command lines must work correctly before you put them in the script; try them out at a shell prompt first. 7a. Create a new directory with the name (note the blank): My Dir (You will have to hide the blank in the name from the shell.) 7b. Make the My Dir directory the current directory in the script. (Again, remember to protect the blank in the name from the shell.) 7c. Display the name of the current directory on the screen. 7d. Put a sorted copy of the Unix password file into the current directory under the new name of "password_sorted.txt". 7e. Extract just lines 6-10 from the password_sorted.txt file and put the output into a file named "short_password.txt". 7f. Extract the last 5 lines from password_sorted.txt and *append* them to the short_password.txt file. (Appending redirection is demonstrated in the middle of p.94 in your Linux textbook.) 7g. Display on the screen a word count of the 10-line short_password.txt file. (It should have 10 lines!) If you test your script more than once, you will find that you cannot make a directory on top of an existing directory - you will get an error message the second time. You can either ignore the error; or, you can use a Unix command to remove the entire directory (and all its contents) before you run your script a second time. 8. Insert comments in front of each of the above seven command lines in your myscript04.sh file, explaining in your own words what each command line does. Make sure your script still works! 9. Create a file named answer04.txt with your Assignment Label in it. At the end of the answer04.txt file, after the label, do the following: Prepare one-line descriptions in your own words of what the following Unix commands do, and where they are described (either a Linux text page number, a page in your course notes, or a man page). I've done the first command as a one-line example. You do the rest: apropos - locate manual pages by title keyword (Linux p.99) bash - cal - cat - cd - chmod - cp - date - diff - du - echo - file - grep - head - last - less - ls - man - mesg - mkdir - more - mv - passwd - pwd - rm - rmdir - sort - stty - tail - touch - vi - vim - wc - who - 10. Submission. Submit all three files (at the same time) for marking as Exercise 04: myscript04.sh answer04.txt short_password.txt The short_password.txt file is not in the current directory; you will have to specify a relative path into the directory in which it resides. For Exercise 04, always use "04" as the first argument to "submit". Always submit all three files at the same time; do not use three different submit commands. Use one submit command with all three pathnames.