- OPS435 -

OPEN SYSTEM AUTOMATION

Lab #6

FOCUS: Logic & Loops

PART A - Perform the following tasks:

  1. Logon to your Matrix account.
  2. Perform the week6 online tutorial called "Online Linux Tutorials". This tutorial must be completed to count as half of the mark for this lab #6. The tutorial, when properly completed will send your instructor and yourself an e-mail message to verify that the tutorial was completed.

    Here is a link to the online tutorial instructions: [ html ]

  3. Proceed to Part B
  4. PART B - Perform the following tasks:

    1. Logon to your Matrix account. This lab requires that you use your Matrix account in order to submit your lab.
    2. Make an empty directory, called lab06.
    3. Use the cd command to make lab06 your present working directory.
    4. Use a text editor to create a file called lab06.bash and add a shebang line to make it a portable Bash shell script.
    5. Add the following lines displayed below to your existing shell script:


      case $# in
      1) text=$1
      repetitions=5
      ;;
      2) text=$1
      repetitions=$2
      ;;
      *) echo "USAGE: $0 [text][# of repetitions]" >&2
      exit 1
      esac


    6. Save and exit your file called lab06.bash, set execute permissions for your newly-created file lab06.bash.
    7. Run this without any arguments. What happens? What happens when you run the following command displayed below:

      ./lab06.bash 2> error

    8. Issue the following command:

      echo $?

      Try to think of why the value of $? is displayed that way...

    9. Add the following lines displayed below into your shell script:

      for (( x=1;x<=repetitions;x++ ))
      do
      echo "text is $text"
      done


    10. Save changes, and run your shell scripts twice as displayed below:

      ./lab06.bash one

      ./lab06.bash one 3


      Try to understand in terms of the "for" loop what happened for each situation.

    11. Add the following lines to your shell script:

      set this and that
      for x
      do
      echo $x
      done


    12. Run your shell script as displayed below:

      ./lab06.bash one 4


      Try to understand why the above result occurred...

    13. Add the following lines to your shell script:

      answer=y

      until [ "$answer" != "y" ]
      do
      read -p "Do you want to loop again? " answer
      done


    14. Save your changes and run your shell script as shown in step #12. Take time to see how the "until" loop works...
    15. Proceed to Part C

    PART C - Write a shell script
    1. Make certain that you are currently located in the lab06 directory
    2. Create a portable bash shell script called testFilePathname.bash
    3. Make certain that your shell script contains the appropriate shebang line.
    4. Add logic to force the user to enter AT LEAST one argument after your shell script. If there are zero arguments, you need to display a USAGE statement (as standard error), and terminate your shell script with a FALSE value.
    5. Use a loop that will run for EACH ARGUMENT after your shell script name (i.e. a positional parameter) and display the argument followed by a message if that file is or is NOT a regular file. Refer to sample run below:


      PROVING FILES EXIST (OR NOT)
      ls a b c
      ls: cannot access a: No such file or directory
      ls: cannot access c: No such file or directory
      b

      RUN #1
      ./testFilePathname.bash
      USAGE: [file pathname(s)]

      RUN #2
      ./testFilePathname.bash a b c
      a is not a regular file
      b is a regular file
      c is not a regular file

    6. Save your changes, and run your shell script to make certain it works...
    7. Proceed to Part D to submit your lab...

    PART D - Submit your Lab #6:
    1. Make certain that you are currently located in the lab06 directory
    2. Issue the following Bash Shell script to check and if correct, send e-mail to your OPS435 professor (works only for Murray Saul's sections):

      /home/murray.saul/labs/submit-lab6.bash

      This shell script should either indicate problems and hints for you to correct your shell script, or indicate that your lab #6 submission was successful. If your lab was successfully submitted, both you and your OPS435 professor (Murray Saul) should have received an e-mail message.

      Note: Keep this e-mail message for the remainder of the semester as date and time stamp proof that you submitted the lab in case there is a discrepancy with your OPS435 lab grade...