------------------------ Exercise #03 for NET2003 due January 20, 2006 ------------------------ -Ian! D. Allen - idallen@idallen.ca [ *** minor updates made 12h30 January 19 *** ] 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: 23h59 Friday January 20, 2006. The deliverables for this exercise are to be submitted online on the Course Linux Server using the "netsubmit" 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 late but before 12h00 (noon) on Monday, January 23. 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. Exercise Synopsis: Create a list of known Unix commands. Create an executable shell script. Where to work, location of the course notes on the Course Linux Server, exercise preparation: See exercise01.txt for all the above details. NOTE: For full marks, keep your lines shorter than 80 columns in this course! --------------------------------------------- Exercise Details (on the Course Linux Server) --------------------------------------------- 0. Have you done all the preparation steps? If not, go back and do them. You may find it useful to create separate directories in your account to store the files for each exercise. Part I - exercise03cmds.txt ------ 1. Fetch a copy of the unix_command_list.txt file from the course notes directory to your own home (current) directory. 2. 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.) 3. 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 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. Do not copy. 4. At the top of the file, create an Exterior Assignment Submission label following the example you will find under the "Assignment Standards" button on my teaching home page (teaching.idallen.com). 5. Preface each of the seven lines of the label with the two characters "# " (octothorpe+space). The lines do not have to be numbered. 6. Rename the file to be called: exercise03cmds.txt Part II - exercise03script.sh ------- You will build an executable shell script containing a list of Unix commands to be executed. 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: exercise03script.sh Make the file executable using the chmod command (note the plus): chmod +x exercise03script.sh 2. At the top of the exercise03script.sh file, fix the existing Assignment Submission label comment to be your own label. Make sure the lines of the label start with the shell comment character '#'. 3a. Delete the line (line 2) starting with "# Display on standard error ...". 3b. At the top, under "Syntax", replace [args...] with (no arguments) 3c. Put a comment character in front of the line beginning "LANG=C; ..." 4. At the top, under "Purpose", replace the paragraph with a short description of what this script does (come back to this - see below). 5. Delete everything below and after the line "umask 022" and replace it with executable command lines (containing one or more commands joined by Unix pipes) that will do the actions described below. For example, to show "a count of the number of users logged in" you would echo the question number, enter a comment line, and enter the correct command pipeline into the bottom of the script file: echo "--- Question 5z" # display a count of the logged in users on this machine who | wc You may want to open up another 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. Test your script periodically (after each edit) by saving it and running it from the command line (perhaps in a different window): $ ./exercise03script.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. a) Display this text on your screen: This is an executable shell script. b) Execute a command that shows the name of this computer. c) Execute a command that shows the current working directory. d) Execute a command that shows the current time and date. e) Execute a command that shows the calendar for the month and year you were born. f) Execute a command that shows the disk usage for the /bin directory. g) Execute a command that shows what type of file /bin/ls is. (It should tell you that it is an ELF 32-bit executable.) h) Display a count of the lines, words, and bytes in the file /etc/passwd. i) Copy the file /etc/passwd to the current directory. (The file should be named "passwd" in the current directory.) j) Rename the copied file to be: mypasswd k) Display on the screen only the last 5 lines from the mypasswd file. l) Display on the screen only the first 5 lines from the mypasswd file, in ASCII sorted order. m) Display on the screen only lines 5-10 from the mypasswd file. (Verify that the correct number of lines are output!) n) Create a new empty file named: myempty o) Generate a long listing of the file myempty that shows (among other things) the owner of the file and its size and modify time. p) Remove the file named myempty. q) Create a command pipeline that outputs the count of the number of manual page titles that contain the keyword "file". (A count of approximately 1457 lines.) Class Notes: man_page_RTFM.txt r) Create a command pipeline that outputs the count of the number of manual page titles that contain the keyword "file" that are in section (1) of the manual. (A count of approximately 330 lines.) Class Notes: man_page_RTFM.txt s) Create a command pipeline that outputs the count of the number of pathnames (including all subdirectories) that lie under the /usr/bin directory. (A count of approximately 1969 names.) t) Sort the list of users currently logged in to the machine and display just the one line containing the userid that sorts last. u) Output the line "Pausing..." and then have the script pause for 2 seconds. (This is two separate commands!) v) Last command: Cause the script to exit. 6. 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: $ ./exercise03script.sh 7. Above each of the lines in your working script, make sure you have added a line that echoes the question number. Under that echo line, add 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 5z" # display a count of the logged in users on this machine who | wc 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.) Scripts without comments will not be marked. NOTE: For full marks, keep your lines shorter than 80 columns in this course! Submission ---------- Class Notes reference: netsubmit.txt - Using the netsubmit command Submit the output and the finished and labelled files for marking as Exercise 03 on the Course Linux Server, using the following netsubmit command line: $ netsubmit 03 exercise03cmds.txt exercise03script.sh This "netsubmit" program will copy the files to me for marking. Always submit *both* files at the same time. Read netsubmit.txt