COMP2101

Lab 5 - Advanced Scripting

Practice Scripts

Using functions

This exercise practices working with functions in scripts.

firstfunctions.sh

This exercise practices working with functions in scripts.

  1. Download the firstfunctions.sh script
    wget -O ~/bin/firstfunctions.sh https://zonzorp.github.io/COMP2101/Labs/bash/scripts-lab5/firstfunctions.sh
    chmod +x ~/bin/firstfunctions.sh
    
  2. Run it to see what it does
    firstfunctions.sh
    
  3. Modify the script to be do the task described in the comments in the script.
  4. Test your changes to be sure they work
    vi ~/bin/firstfunctions.sh
    firstfunctions.sh
    

Working with signals

countdown.sh

This exercise practices working with signals in scripts.

  1. Download the countdown.sh script
    wget -O ~/COMP2101/bash/countdown.sh https://zonzorp.github.io/COMP2101/Labs/bash/scripts-lab5/countdown.sh
    chmod +x ~/COMP2101/bash/countdown.sh
    
  2. Run it to see what it does
    countdown.sh
    
  3. Modify the script as described in the comments in the script.
  4. Test your changes to be sure they work
    vi ~/COMP2101/bash/countdown.sh
    countdown.sh
    

Working with unpredictable data in loops

sysconfig.sh

This script is designed to provide useful information about your system in a simple summary report. This exercise practices working with hardware info and signals in scripts.

  1. Download the sysconfig.sh script
    wget -O ~/COMP2101/bash/sysconfig.sh https://zonzorp.github.io/COMP2101/Labs/bash/scripts-lab5/sysconfig.sh
    chmod +x ~/COMP2101/bash/sysconfig.sh
    
  2. Run it to see what it does
    sysconfig.sh
    
  3. Modify the script as described in the comments in the script.
  4. Test your changes to be sure they work
    vi ~/COMP2101/bash/sysconfig.sh
    sysconfig.sh
    
  5. If anything didn’t work correctly, go back, fix the issues and repeat until it does work right.
  6. Save the final version of your script to your github repository (stage, commit, push).

Graded Script - Bash Assignment:

To be marked for the bash portion of the course, you are required to create a script and a function library that incorporates evrything you have learned about bash scripting. You may reuse pieces of scripts you already created in previous lab activities.

Environment

Your script and your function library are required to be in the bash folder of your cloned repository. You PATH should include that folder automatically when you log in.

Function Library

Your function library file must be called reportfunctions.sh and only contain function definitions, and not be an executable shell script. Your function library file must contain functions to perform generation of the individual outputs listed:

System Report Script

Your system report script must be an executable script named systeminfo.sh. Your script must source your function library file and not contain code to perform tasks the functions perform. Your script should handle errors gracefully, check for root permission, and append errors with a timestamp to a logfile named /var/log/systeminfo.log. Your error messages should be human friendly and be handled using the errormessage function. Your script must contain comments to describe the purpose of the script and explain any non-trivial things your script does. The default behaviour of your script when run without any command line options is to print out a full system report using all of your function library functions. Your script must support the following command line options:

Grading

When your script, function library file, and modified environment file are completed and pushed to your github repo (all 3 files need to be pushed), go to Blackboard and click submit, entering the URL for your repo (https://github.com/yourgithubusername/COMP2101) as a text comment. If I cannot see your files on your github repo, I cannot give you marks for it. Late submissions will not be accepted. No exceptions.