----------------------- Lab #03 for NET2003 due January 29, 2007 ----------------------- -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: before 10h00 Monday January 29 The deliverables for this lab exercise are to be submitted online on the Course Linux Server using the "netsubmit" method described in the lab exercise description, below. No paper; no email; no FTP. Late-submission date: I will accept without penalty lab exercises that are submitted late but before 12h00 (noon) on Wednesday, January 31. After that late-submission date, the lab exercise is worth zero marks. Lab 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. Lab Synopsis: Update your list of known Unix commands. Create an executable shell script. NOTE: For full marks, keep your lines shorter than 80 columns in this course. Short lines allow for easy printing and side-by-side comparison of files on a screen. Where to work: See Lab #1. Easy access to Course Notes: See Lab #1. ---------------------------------------- Lab Details (on the Course Linux Server) ---------------------------------------- Make sure you are working on the Course Linux Server. You can do this work on Knoppix; however, it will disappear when you log off unless you copy it to the Course Linux Server. *) For full marks, keep your lines shorter than 80 columns in this course. Short lines allow for easy printing and side-by-side comparison of files on a screen. *) You may find it useful to create separate directories in your linus server account to store the files for each lab exercise, e.g. $ mkdir lab3 $ cd lab3 $ vim lab03cmds.txt Part I - lab03cmds.txt ------ Make sure you are working on the Course Linux Server. You can build this file on Knoppix; however, it will disappear when you log off unless you copy it to the Course Linux Server. A. Fetch a copy of the updated unix_command_list.txt file from the course notes directory to your own directory on the Course Linux Server. (See "Easy access to Course Notes", above.) B. Remove all the leading numbers from the lines. (Deleting a word is a two-character command in VIM.) (Tip: In command mode, a period repeats the last change you did in VIM.) C. Below each command name, enter a line that starts with a dash followed by a short, one-line summary of what the command does, written in your own words. (You may already be keeping this list as part of your class notes. RTFM as needed.) The single line must be a short summary less than 80 characters. Example format: chmod - change the permissions (mode) of a file or directory fdisk - display or change disk partition information Use your own words; do not copy words from the manual pages or from other students. Use your *own* words, not a copy. Make the summary one line in your own words, less than 80 characters. D. At the top of the file, create an Exterior Assignment Submission label. E. Preface each of the seven lines of the label with the two characters "# " (octothorpe+space). The lines do not have to be numbered. F. Rename the file to be called: lab03cmds.txt (The Unix rename command is called "mv" - see "man mv".) Part II - lab03script.sh ------- You will build an executable shell script containing a commented list of Unix commands to be executed. Make sure you are working on the Course Linux Server. You can build this script on Knoppix; however, it will disappear when you log off unless you copy it to the Course Linux Server. In shell scripts, lines starting with octothorpe characters ('#') are ignored as comment lines. 1. Fetch a copy of the argv.sh.txt file from the course notes directory (copy the file) and rename your copy to be: lab03script.sh Make the file executable using the chmod command (note the plus): $ chmod +x lab03script.sh 2. Verify that the copied script executes correctly and without error: $ ./lab03script.sh a b c ./lab03script.sh: This script has 3 command line arguments. Argument 0 is [./lab03script.sh] Argument 1 is [a] Argument 2 is [b] Argument 3 is [c] 3. At the top of the lab03script.sh file, fix the existing Assignment Submission label comment to be your own label. Make sure the lines of the label all start with the shell comment character '#'. 4. Delete the line (line 2) starting with "# Display on standard error ...". 5. At the top, under "Syntax", replace "[args...]" with "(no arguments)" so that the line reads: # $0 (no arguments) This script takes no command line arguments. 6. At the top, under "Purpose", replace the paragraph with a short description of what this script does (come back to this - see below). Don't forget this step! 7. Change the line starting with PATH= to be this exact line below by adding "/sbin" and ":" to the start of the PATH string: PATH=/sbin:/bin:/usr/bin ; export PATH Do not add any blanks or quotes to this line. Make sure you see the two characters ":" and ";" as different. (Adding /sbin to the PATH allows the shell to find executable commands in the /sbin directory as well as in /bin and /usr/bin .) At this point, you might re-execute the script to make sure you haven't introduced any typing errors. The output should be the same as above. There should be no error messages on the screen. 8. Delete everything below and after the line "umask 022" in the file. 9. Add a blank line after "umask 022". 10. Delete all the "I!" comment lines. Never submit these lines in your own scripts - they are "instructor" comments from me to you. 11. You will now add, to the bottom of this executable script, three lines for every section in this question. The first line will echo the question number onto the screen in the exact format shown. The second line will be a shell comment that will not print on the screen. The third line will be a shell command that will do the action required by the question. The output from the command will appear on the screen, if the command generates output. (Many Unix/Linux commands work silently and have no output on the screen.) For example, if asked to display "the current time and date" you would echo the question number, enter a comment line, and enter the correct Unix/Linux command into the bottom of the script file like this: echo "--- Question 11b" # display the current date and time date Use the exact format and syntax shown for the echo line that shows the Question number. (Use the cut-and-paste features of vim to copy the line for the next question; don't re-type it every time!) Keep the comment short - exactly one line, less than 80 columns. You may want to open up another login window and work with the shell interactively to test the commands you come up with. Copy each working command into the shell script as you debug it in the interactive window, and run the script after each addition. As you write the script, leave one blank line between each question you answer, to make the script source more readable. The result will be groups of three lines, separated from one another by one blank line. Test your script periodically (after each edit) by saving it and running it from the command line (perhaps in a different window): $ ./lab03script.sh Make sure there are no error messages. Run the script after each edit you add; that way you debug only the few lines you added. NOTE: Do not use any "change directory" commands in your script unless the instructions ask for it explicitly. Do not add commands or create output that is not required. Do only the commands listed, in the order listed. If you can't answer a question: echo the question number, add the comment line, but leave out the actual command itself. Here are the individual questions to add to your executable script. Find executable commands that look up and produce the given output. All the command names needed are in the Notes file: unix_command_list.txt 11 a) Display this text on your screen: This is an executable shell script. (Note: Spelling and punctuation count! Be precise.) b) Show the name of this computer. c) Show the calendar for September 1752. d) Show the disk usage (file space usage) for the /bin directory. (Approximately 4640 blocks.) e) Show a list of all the absolute pathnames, recursively, that are under the directory /etc/X11/fonts (Nine absolute pathnames, including five directories, should display.) f) Execute a command that shows what type of file /bin/ls is. (It should tell you that it is an ELF 32-bit executable.) g) Display a count of only the lines and words in the file /etc/passwd. (The command that does this kind of thing usually also prints the number of bytes - make sure only the lines and words are counted.) (At least 65 lines; maybe more by the time you read this.) h) Display on the screen only the last 2 lines from the /etc/passwd file. i) Display on the screen only the first 2 lines from the /etc/passwd file. j) Search in the titles of all manual pages for the keyword VPN3000 (At least three manual page title lines will display.) k) Display only the line(s) containing the string "root" that is/are found in the file /etc/passwd (At least one line) l) Using the command name given in the course notes, display the checksum of the bytes in the /etc/iftab file. (The output will start with a five-digit number 34795.) m) Remove a pathname named "foobar" recursively, including all files and subdirectories that might lie under it. Find a way to suppress the error message you get if the "foobar" directory is nonexistent. n) Create a new (empty) directory named "foobar" (without the quotes). (This directory making command will always succeed, if you have done the previous step correctly.) o) Make "foobar" the current directory. (In other words, change into the "foobar" directory.) p) Create a new empty file named: myempty q) Create a new (empty) directory named "subdir". r) Make "subdir" the current directory s) Execute a command that shows the current working directory. (The name should end in "foobar/subdir".) t) Move the file named myempty from the parent directory into the current directory under the four-character name: .foo (This is a command that does a move/rename operation, not a copy.) u) Generate a long listing of the file /etc/iftab that shows (among other things) the owner of the file and its size and modify time. v) Copy the file /etc/iftab into the parent directory under the name: happy (Copy it to the parent of the script's current directory, not to the parent directory of /etc/iftab.) w) With only one single command, show the directory list of *all* names (including hidden) in the current directory and in the parent directory. (Three names will display under the current directory; four names will display in the parent directory.) x) Display the checksum of all files ending in "sh" in the directory /bin. Use the given command name from the course notes, and use a shell GLOB pattern to generate the file names. (The output is five lines, with five-digit checksum values starting each line.) y) With one command, remove the files ".foo" and "happy" that you created in this script. (There should be no files left anywhere under the foobar directory or any sub directories.) z) Last command: Cause the script to exit. All the command names needed are in the Notes file: unix_command_list.txt 12. Execute your script as you add each of the above command lines. Make sure the script generates the correct output and no errors when you execute it: $ ./lab03script.sh 13. Verify the script format. Above each of the lines in your working script, make sure you have added a line that echoes the question number in the exact format given. Under that echo line, make sure you have 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 11z" # exit the shell script with a good status of zero exit 0 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.) 14. Go back and finish the Purpose section comment at the top of the script. Scripts without your added comments will not be marked. NOTE: For full marks, keep your lines shorter than 80 columns in this course! Submission ---------- 15. Submit the above two files (see below). Submission Standards: See Lab #1 for details. A. Make sure both files contain an Exterior Assignment Submission label. For full marks, lines must be shorter than 80 columns. B. Submit your files for marking as Lab 03 using the following *single* netsubmit command line exactly as given here: $ netsubmit 03 lab03cmds.txt lab03script.sh Always submit *all* files at the same time for every submission. Files submitted under the wrong names are worth zero marks. P.S. Did you spell all the assignment label fields and file names correctly?