- OPS435 -

OPEN SYSTEM AUTOMATION

Lab #3

FOCUS: Variables

PART A - Perform the following tasks:

  1. Logon to your Matrix account.
  2. Perform the week3 online tutorial called "Online Linux Tutorials". This tutorial must be completed to count as half of the mark for this lab #3. 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

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 lab03.
  3. Use the cd command to make lab03 your present working directory.
  4. Use a text editor to create a file called lab03.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:

    echo "Enter your age (in years): " # Prompt user for age
    read userAge
    echo "You are $age year(s) old..." # Display user's age

  6. Save and exit your file called lab03.bash, set execute permissions for your newly-created file lab03.bash, and run this file.
  7. You should notice that your Bash shell script does NOT run properly. Carefully view your shell script to see where the problem is, correct, and re-run the Bash shell script until it runs properly.
  8. After you have made changes to allow shell script to run properly, you may have noticed that the shell script prompts the user for age, but the cursor is displayed on the next line. To fix this, add the option "-n" to your echo command to prevent the echo statment going to the next line prior to your read statement. Please do this now and re-run to make certain it works.
  9. After you have confirmed it works, remove that echo command to prompt the user for age, and edit your read command with an option and text to prompt the user for age. Hint: use the man pages on the read command.
  10. Add a comment at the end of the newly modified read command explaining to "Prompt the user for age"
  11. Re-run your shell script to make certain that the shell script works correctly...
  12. Let's add a command ABOVE your last echo command which will use an ENVIRONMENT variable to display the user's name before displaying the user's age. Enter the following command in your shell script which is displayed below:

    echo -n "Hello, "
    finger $USER | head -1 | cut -d":" -f3

  13. Run the shell script and verify that it works correctly... Notice how useful ENVIRONMENT variables are in shell scripts. Add another echo statement using another ENVIRONMENT variable (other than $USER), and re-run your shell script to make certain that it works...
  14. Proceed to Part C.

PART C - Perform the following tasks:
  1. Make certain that you are currently located in the lab03 directory
  2. Create a file called data.txt that contains the following data:

    This is the first sentence
    This is the second sentence
    The temperature this day is cold
    I'm felling cold
    When is spring going to arrive?

  3. Create a portable bash shell script called find.bash
  4. Make certain that your shell script contains the appropriate shebang line.
  5. Enter the following lines below into your shell script:

    echo "\$1 variable is $1" # Display first positional parameter
    echo "\$2 variable is $2" # Display second positional parameter

  6. Save your file, assign execute permissions, and see what happens when when you run this command. Why don't you see the values for $1 and $2? Because you didn't run the shell scripts with any arguments!
  7. Now, run the same command with the following arguments:

    find.bash Seneca College

  8. Add the following lines to the bottom of your shell script:

    echo
    echo "Here are the contents of my file called $2"
    echo
    cat $2

  9. Save your work and issue the following command with 3 arguments:

    find.bash $USER data.txt

  10. Add a command (using positional parameters) that will use the first arugment from YOUR shell script command as a pattern to match, and the second arugment as the filename data.txt. This command will use the grep command (with -i option) to display all lines that match the pattern (first arugment) in the file input.txt (second argument).

    Here is a sample run (command is in bold):

    find.bash This data.txt
    $1 variable is This
    $2 variable is data.txt

    Here are the contents of my file called data.txt:

    This is the first sentence
    This is the second sentence
    The temperature this day is cold
    I'm felling cold
    When is spring going to arrive?

    Here are the lines matching This:

    This is the first sentence
    This is the second sentence
    The temperature this day is cold


  11. Proceed to Part D

PART D - Submit your Lab #3:
  1. Make certain that you are currently located in the lab03 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-lab3.bash

    This shell script should either indicate problems and hints for you to correct your shell script, or indicate that your lab #3 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...