Scripting Languages: Assignment 2.1- Portfolio Task 1
In this assignment you are required to write four (4) scripts that will demonstrate the extent to which you have understood the shell scripting concepts and practices addressed in Modules 1 to 5 inclusive. Each task is worth five (5) marks for a total assignment value of 20 marks. These portfolio tasks will help you build capacity for implementing the final main assessment.
- Your script will be marked on a standard Linux installation using the bash shell.
- You must only use bash shell script as covered in lectures and workshops.
- Refrain from using non-core commands, tools and utilities in your bash shell scripts. Non-standard bash commands, tools and utilities will not be downloaded and installed by your tutor.
- Ensure each script you write is fully self-contained and is not configured to be dependent on external files, libraries or resources to run.
- Do not use the trap command in any of your scripts.
- Each script you submit must contain your full name and student number at the beginning as code comments.
- This is an individual assignment only and must not be completed in collaboration with other students
- You may not work with others, acquire code from others, or provide code to others
- Further, you may not post any of the assignment tasks below to a code-development community of any kind seeking solutions or advice
- Nor may you copy and paste or otherwise reproduce code provided by external sources and use it as part of your own solutions
- Where it is found that any of these restrictions have been ignored, academic misconduct proceedings will be initiated
- Please read the checklist below and watch the associated video BEFORE submitting your assignment
Write a script that calculates the sum of three (3) integers passed to it through the command line and display this to the terminal. If however this sum exceeds 30, give the user a warning indicating this and then exit the script.
- Call the script calcsum.sh
- When the script is run, your tutor will enter three (3) integers on the command line, e.g.
./calcsum.sh 5 10 12. These are example values only, so do not hard-code these into your script. Your tutor will use different values when marking your script.
- If the sum of the integers passed is less than or equal to 30, the output of the script to the terminal will appear as follows:The sum of x and x and x is x
where x represents the integers passed to the script when it is run and their calculated sum. However, if the sum of the integers passed is greater than 30, the output of the script to the terminal will appear as follows:
Sum exceeds maximum allowable
- In either case, your script will then terminate.
- Your script must use bash default variables to hold the passed integers and as arguments in the sum calculation. You may only create a custom variable for the sum of the integers.
- There is no need for input validation in this script; your tutor will enter three (3) integers as required when the script is run.
Write a script that when run, prompts the user to enter a two digit numeric code (integer) that is either 20 or
No other inputs are to be accepted as valid except the integers 20 or 40.
- Call the script validint.sh
- The value input by the user must be validated to ensure that it is:
- an integer, and
- one of the two integers specified above
- In the event that the input entered by the user is invalid, they are to be advised of such and prompted to try again.
- In addition to entering valid values, your tutor will test your validation by also entering:
- An integer that is not one of the two specified above
- A string, e.g. helloworld
- A null value (by just pressing enter)
- Your script must detect and reject these invalid inputs and prompt the user to try again.
- The input process must continue until one of the two integers specified above is entered. Do not allow the script to terminate until this occurs.
- Once one of the two allowable integers has been entered by the user, echo a message to the screen that a valid input has been made and then terminate the script at this point.
Write a script that counts the number of files and child directories within a specified directory according to a specified property.
- Call the script countdf.sh
- When the script is run, the path to a directory will be used by your tutor at the command line, e.g.
./countdf.sh ~/CSI6203/backups/june2020. This is an example path only, so do not hard- code it into your script. The directory specified by your tutor will contain:
- a number of text files that contain data
- a number of text files that do not contain any data
- a number of child directories that themselves contain files and directories
- a number of child directories that are themselves empty
- The output of the script to the terminal will appear as follows:
The [dirname] directory contains:
x files that contain data
x files that are empty x non-empty directories x empty directories
where [dirname] represents the directory of your tutor’s choosing and x represents the number of files and directories found matching each criterion.
- Be sure that the script can be run from any directory it is placed in within your tutor's Linux user directory structure.
- Use an appropriate loop structure in conjunction with file and directory test commands to achieve this outcome. Do not use the find command in your task solution.
- Do not count files or directories that exist within any of the child directories.
- There is no need for data validation in this script; your tutor will enter a full path/directory that does
exist and within which a range of files and child directories also exist.
Write a script that allows the user to search for specific lines in a server access log according to a pattern they provide and have these lines written to a new file for further use.
- The pattern to be searched for
- Whether they want an whole word match or any match on the line
- If they want to do an inverted match