----------------------- Lab #02 for NET2003 due January 22, 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 22 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 24. 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: Create a 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 lab2 $ cd lab2 $ vim lab02cmds.txt Part I - lab02cmds.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 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: lab02cmds.txt (The Unix rename command is called "mv" - see "man mv".) Part II - lab02script.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: lab02script.sh Make the file executable using the chmod command (note the plus): $ chmod +x lab02script.sh 2. Verify that the copied script executes correctly and without error: $ ./lab02script.sh a b c ./lab02script.sh: This script has 3 command line arguments. Argument 0 is [./lab02script.sh] Argument 1 is [a] Argument 2 is [b] Argument 3 is [c] 3. At the top of the lab02script.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): $ ./lab02script.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. 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: 11 a) Display this text on your screen: This is an executable shell script. (Note: Spelling and punctuation count! Be precise.) b) Display the current time and date. c) Copy the file /etc/passwd to the file "mypasswd" in the current directory. d) Show the list of files in the current directory. e) Rename the copied file to be: junk f) Show the list of files in the current directory. g) Rename the file junk to be /tmp/abcd0001 where abcd0001 is actually your login userid. (Don't use abcd0001.) h) Show the list of files in the current directory. i) Display the entire contents of file /etc/iftab without any pagination. (Don't use "less" this time.) j) Show the network interface configuration for eth0 (only). (Do not show the loopback configuarion; only show eth0.) k) Copy the file unix_command_list.txt from the course notes directory into the current directory under the name list.txt l) Display the reverse-sorted contents of the list.txt file. (The lines of output should be in ASCII descending order, with blank lines appearing last. RTFM) m) Remove the file list.txt using the command "rm" - see "man rm". n) Fetch this WWW URL into the current directory: http://localhost/distributions/Knoppix/KNOPPIX_V5.1.1CD-2007-01-04-EN/knoppix-cheatcodes.txt o) You may want to review the contents of the Notes file man_page_RTFM.txt so you can answer this next question: Display on the screen (but do not execute) the command line you would use to show the passwd file format from section 5 of the manual. The script should show the command that would be used; it must not actually execute that command (because the output would be a lot of pages). p) Rename the file knoppix-cheatcodes.txt to be the four-character name ".foo" (without the quotes). Note the leading period on .foo q) Show the list of files in the current directory. (The file you named .foo above will not be shown; files starting with periods are hidden or ignored files.) r) Show the list of *all* the files in the current directory, including hidden and ignored files that start with a period. RTFM to get the command option that does this. The file you named .foo above will be in the output of this command line. s) Remove the file named .foo t) Last command in your script file: Cause the script to exit. (There is no section 1 man page for this command; because, it is built-in to the shell and documented in the man page for the shell.) 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: $ ./lab02script.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" # display the name of the current machine hostname 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 02 using the following *single* netsubmit command line exactly as given here: $ netsubmit 02 lab02cmds.txt lab02script.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?