- OPS435 -

OPEN SYSTEM AUTOMATION

Lab #4

FOCUS: Additional Shell Scripting Tools

PART A - Perform the following tasks:

  1. Logon to your Matrix account.
  2. Perform the week4 online tutorial called "Online Linux Tutorials". This tutorial must be completed to count as half of the mark for this lab #4. 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 lab04.
  3. Use the cd command to make lab04 your present working directory.
  4. Use a text editor to create a file called lab04.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:


    touch b c
    mkdir a 2> /dev/null # Create and change to subdirectory
    cd a
    touch x y z

    clear

    echo
    echo "Here are the contents of my home directory:"
    echo
    echo "Here are the contents of my current directory:"
    echo
    echo "Here are the contents of my previous directory:"
    echo


  6. Save and exit your file called lab04.bash, set execute permissions for your newly-created file lab04.bash, and run this file.
  7. Modify your shell script to run the ls commands using the ~, ~+, and ~- shell expansion symbols BELOW each corresponding echo statement to display the contents of each directory contents. Then save and run your shell script to verify results.
  8. Modify your shell script to MOVE the above-mentioned ls commands INTO the above "echo" statements by using command substitution
    (i.e. $( ) - refer to OPS435 notes if you do not know how to use command substitution ).
  9. Save and run your shell script. Notice how the results differ from previous modification...
  10. Use a read statement to prompt the user for your first name and store it in a variable called userName.
  11. Add the following lines displayed below your read statement you just inserted:

    echo
    echo "Number of characters contained in \"$userName\": ${#userName}"
    echo "Characters 2 to 4 cut out from \"$userName\": ${userName:1:3}"

  12. Save and run your shell script to view the results.
  13. Add the following line in your shell script:

    numberOfFiles=$(ls | wc -l) # Method to store command substitution results into a variable
    echo
    echo "Number of files in current directory \"$PWD\" are: $numberOfFiles"

  14. Save and run the shell script and verify that it works correctly.
  15. Add the following lines below into your shell script:

    echo
    read -p "Enter number 1: " number1
    read -p "Enter number 2: " number2
    echo
    echo "Number 1 + Number 2 = $((number1 + number2))"
    echo "Number 1 - Number 2 = $((number1 - number2))"
    echo "Number 1 * Number 2 = $((number1 * number2))"
    echo "Number 1 / Number 2 = $((number1 / number2))"
    echo "Number 1 % Number 2 = $((number1 % number2))"

  16. Save and run your shell script and verify the results.
  17. Proceed to Part C

PART C - Write a shell script
  1. Make certain that you are currently located in the lab04 directory
  2. Create a portable bash shell script called info.bash
  3. Make certain that your shell script contains the appropriate shebang line.
  4. In your shell script, you need to add in a separate echo statement to determine the following pieces of information:



    (HINT: Use ENVIRONMENT VARIABLES, but use COMMAND SUBSTITUTION twice for last name, first name. You may also want to use pipes for one of these commands as well...)

    Use the format such as:

    "The hostname is: ....."
    "The current username is: ......"
    "The user's names is ... first name lastname"

  5. Save, set execute permissions, and run your shell script to verify it works.
    Your instructor will be checking when submitted to see if shell script works!
  6. Proceed to Part D to submit your lab...

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

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