Assignment 6
Home ] Assignment 2 ] Assignment 3 ] Assignment 4 ] Assignment 5-A ] Assignment 5-B ] [ Assignment 6 ] Assignment 7 ] Errata / Updates ] Using Telnet ] Old Announcements ]
Updated:
1999-11-20 12:47

Home

Assignment 6 - UNIX - Section 040

This assignment is Assignment 6 for Section 040 - Ian Allen.

Hand in: The telnet log sheet from the last Hand In step in hard copy form.

Preparations:
    You must understand Chapter 22 (Week 10) to do this assignment.


Step 1.  (Readings in Chapter 22)

Use vi to create an answer file named c22answers containing answers to the following questions listed in the Week 10 Reading Exercises.  Put your name on the first line of the file.  Answer only the following questions:
  • Answers to the Chapter 22 Reading Questions 22-1 through 22-8.

Make sure that your name is located at the top of the file.

Step 2.  (Based on Chapter 22)

Develop the checkuser script file (see pages 912-921 of the text).  Debug it until it works without errors.  When it work without errors, try the script with the following command line:
checkuser "This argument contains blanks"

Does the script generate error messages?  Fix the script so that it does not generate error messages when the argument contains blanks or other special characters.  (See "Quoting Multiple-Word Arguments" on page 950.)

Step 3.  (Based on Chapter 22)

Develop the scriptarg script file (see pages 918-919 of the text).  Debug it until it works without errors.  When it work without errors, try the script with the following command line (pay attention to the quotes):

scriptarg "Does this work with" "*" "?"

Does the script handle the special characters in the arguments correctly?  Are they correctly echoed in the output?  Fix the script so that it does not expand special characters in the arguments when it runs.  (See "Quoting Multiple-Word Arguments" on page 950 and "Quoting Special Characters" on page 960.)

Step 4.  (Based on Chapter 22)

Work through Sections 22.5-22.9 (see pages 923-948 of the text) and create the menu shell script.  (Make sure you name your menu shell script with a name that isn't already a Unix command or alias.  If you find that there is already a menu command or alias, name your script something else, e.g. menu1.)

Note: Read carefully section 22.9 on the use of indentation in your script!  Follow the indentation examples used in the text.  Scripts that are not easy to read cannot be understood or marked.  Your finished script should follow the indentation pattern of the scripts given starting on page 984.

Test each of the six menu entries, in order.

  • To test menu item 4, enter this file name: /etc/resolv.conf
  • To test menu item 5, enter the name of your profile file: .profile
    If you don't have a profile file, create one first.

Step 5.  (Based on Chapter 22)

Based on the knowledge learned in the above three script files, write a script file named menu2 that will loop to accept menu selections from the user.  Create five menu selections that perform the following actions:

  1. Display the first 4 lines of /etc/passwd    (Note the number of lines!)
  2. Display the last 3 lines of /etc/passwd    (Note the number of lines!)
  3. Search in file /etc/passwd for lines matching a pattern and display the lines found.  The user will be prompted for the pattern to search for.  Test this menu entry with your userid as the pattern.  Test it again with a single asterisk  * as the pattern.  (There are four lines in the ACADAIX password file that contain asterisks.)
  4. Search in file /etc/passwd for lines that do not contain a pattern and display only a count of the number of lines that do not contain the pattern.  (Select the correct command options to count the lines and to select the lines that do not match the pattern.)    The user will be prompted for the pattern to search for.  Test this menu entry with the pattern: ksh (counts 15 lines that do not contain ksh).  Test it again with the digit zero as the pattern (counts 9 lines that do not contain the digit zero).
  5. This last menu selection should exit the script

The script file should state in the header comments:

  • the script name
  • your name
  • the date of creation
  • a short description of the script

Hand In:

Start telnet logging to record the following session on your A: diskette.  Perform only the following actions, in the following order.  When asked to display a file or script, use the  cat command.  (Do not use an editor or the commands that paginate the file, since the pagination mis-formats the display of the file in the log.)
  1. Display your USER environmental variable.  (Only the one variable, not the whole environment!)
  2. Display the date.
  3. Display the c22answers file created in Step 1.
  4. Display the completed checkuser script of Step 2.
  5. Execute the checkuser script with no command arguments.  Type in your own login name when your script prompts you to enter a login name.
  6. Execute the checkuser script with a single command line argument that is your login name.
  7. Execute the checkuser script with this command line (pay attention to the use of quotes):
    checkuser "This argument contains blanks"
  8. Display the completed scriptarg script of Step 3.
  9. Execute the scriptarg script with this command line (pay attention to the use of quotes):
    scriptarg "Does this work with" "*" "?"
  10. Display the completed menu script of Step 4.
  11. Execute the menu script of Step 4 and test each of the six menu items, in order, using the testing data given in Step 4.
  12. Display the completed menu2 script of Step 5.
  13. Execute the menu2 script of Step 5 and test each of the five menu items, in order, using the testing data given in Step 5.  (Some menu items require more than one test.)
Stop logging and print the telnet log file for handing in.  This one log file is the only thing you should hand in.


Web Author: Ian! D. Allen idallen@ncf.ca
Updated: 1999-11-20 12:47