Scripting Languages: Assignment | My Assignment Tutor

Page 2 of 6Scripting Languages: Assignment 2.1- Portfolio Task 1Due Date: Week 6 – Thursday 31 March 2021 at 17:00 AWSTContentsOverview……………………………………………………………………………………………………………………………………………1GENERAL REQUIREMENTS…………………………………………………………………………………………………………….1IMPORTANT NOTES: …………………………………………………………………………………………………………………….2Task 1 (5 marks)………………………………………………………………………………………………………………………………3Requirements ……………………………………………………………………………………………………………………………..3Task 2 (5 marks)………………………………………………………………………………………………………………………………4Requirements ……………………………………………………………………………………………………………………………..4Task 3 (5 marks)………………………………………………………………………………………………………………………………5Requirements ……………………………………………………………………………………………………………………………..5Task 4 (5 marks)………………………………………………………………………………………………………………………………6Requirements ……………………………………………………………………………………………………………………………..6How to submit your portfolio to Blackboard…………………………………………………………………………………………..6OverviewIn this assignment you are required to write four (4) scripts that will demonstrate the extent to which youhave understood the shell scripting concepts and practices addressed in Modules 1 to 5 inclusive. Each taskis worth five (5) marks for a total assignment value of 20 marks. These portfolio tasks will help you buildcapacity for implementing the final main assessment.GENERAL REQUIREMENTS▪ 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-standardbash 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 externalfiles, 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 codecommentPage 3 of 6Task 1 (5 marks)Write a script that calculates the sum of three (3) integers passed to it through the command line anddisplay this to the terminal. If however this sum exceeds 30, give the user a warning indicating this and thenexit the script.Requirements▪ 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 yourscript. 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 terminalwill appear as follows:The sum of x and x and x is xwhere 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 theterminal 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 sumcalculation. 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 requiredwhen the script is run.Task 1 Marking Key ITEM#ITEMVALUE1The script has been given the name specified, i.e. calcsum.sh0.52Script runs when initiated with command line variables, e.g. ./calcsum.sh 5 10 120.53Bash default variables used for integers provided on command line when script is run0.54Sum of provided integers held in appropriate variable which is used in reporting result toterminal0.55Calculation algorithm used arrives at the correct sum for the three variables provided0.56In the event the sum is less than or equal to 30, the required output for this scenario isprinted to the screen0.57In the event the sum is greater than 30, the required output for this scenario is printed tothe screen0.58Appropriate exit code set upon successful exit of script0.259Shebang line correctly specified and in the correct position0.2510Sufficient code structuring to make script’s elements and their relationship easy torecognise0.511Sufficient commenting to explain how the script’s operation at all stages0.5TOTAL/5 Page 4 of 6Task 2 (5 marks)Write a script that when run, prompts the user to enter a two digit numeric code (integer) that is eitherequal to 20 or equal to 40.Requirements:▪ Call the script validint.sh▪ The value input by the user must be validated to ensure that it is:a) an integer, andb) 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 andprompted to try again.▪ In addition to entering valid values, your tutor will test your validation by also entering:a) An integer that is not one of the two specified aboveb) A string, e.g. helloworldc) 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 notallow 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 screenthat a valid input has been made and then terminate the script at this point.Task 2 Marking Key ITEM#ITEMVALUE1The script has been given the name specified, i.e. validint.sh0.252Script runs when initiated on command line i.e. ./validint.sh0.253Validation rejects integers entered that are not one of the two specified above0.754Validation rejects a string entry0.755Validation rejects a null entry0.756User prompted to try again in each case an invalid value is entered0.57Success message echoed to screen when valid input is made0.58Appropriate exit code set upon successful exit of script0.259Sufficient code structuring to make script’s elements and their relationship easy torecognise0.510Sufficient commenting to explain how the script’s operation at all stages0.5TOTAL/5 Page 5 of 6Task 3 (5 marks)Write a script that counts the number of files and child directories within a specified directory according to aspecified property.Requirements:▪ 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 hardcode it into your script. The directory specified by your tutor will contain:o a number of text files that contain datao a number of text files that do not contain any datao a number of child directories that themselves contain files and directorieso 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 datax files that are emptyx non-empty directoriesx empty directorieswhere [dirname] represents the directory of your tutor’s choosing and x represents thenumber 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 userdirectory structure.▪ Use an appropriate loop structure in conjunction with file and directory test commands to achievethis 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 thatdoesexist and within which a range of files and child directories also exist.Task 3 Marking Key ITEM#ITEMVALUE1The script has been given the name specified, i.e. countdf.sh0.252Script runs successfully when initiated on command line i.e. ./ countdf.sh [path parameter]0.253Script determines the correct number of files that contain data within the specifieddirectory0.754Script determines the correct number of files that are empty within the specified directory0.755Script determines the correct number of non-empty child directories within the specifieddirectory0.756Script determines the correct number of empty child directories within the specifieddirectory0.757Script prints the count results to the terminal in the manner specified0.58Sufficient code structuring to make script’s elements and their relationship easy torecognise0.59Sufficient commenting to explain how the script’s operation at all stages0.5 Page 6 of 6 TOTAL/5 Page 7 of 6Task 4 (5 marks)Write a script that allows the user to search for specific lines in a server access log according to a patternthey provide and have these lines written to a new file for further use.Requirements▪ Call the script searchlog.sh▪ Prompt the user for:a) The pattern to be searched forb) Whether they want an whole word match or any match on the linec) If they want to do an inverted match, i.e. retrieve lines that do not contain the pattern▪ If no match is found, report to the user “No matches found”.▪ If a match is found, echo the number of matches found, e.g. 5 matches found, and then each ofmatching word(s)/line(s) to the terminal with their corresponding line numbers in the sourcefile.▪ In either case, ensure the user has the option to do another search if they so wish or exit the script.▪ Ensure all search options are case-insensitive.▪ To assist you in writing this script, a file named access_log.txt has been supplied with sample serveraccess data. Please note that your tutor will use a file with the same name and structure as theaccess_log.txt file provided, but containing different data. Do not therefore hard-code any of thevalues within the access_log.txt file provided.▪ When your tutor marks your script, the access_log.txt file used will be located in the same directoryas your script when marked. There is no need therefore to prompt for the location of access_log.txtas part of your script.Task 4 Rubric ITEM#ITEMVALUE1Search pattern, match type and invert option all captured from user prior to running search1.02When no matches found, this is detected and message “No matches found” echoed toterminal0.53When matches found, number of matches calculated and echoed to terminal0.54When matches found, matching word(s)/line(s) echoed to the terminal0.55When matches found, their corresponding line numbers in the source file are echoed toterminal0.56All searches are case-insensitive0.57User has option to do another search if they so wish or exit the script0.58Appropriate exit code set upon successful exit of script0.59Sufficient code structuring to make script’s elements and their relationship easy torecognise0.2510Sufficient commenting to explain how the script’s operation at all stages0.25TOTAL/5 How to submit your portfolio to BlackboardSubmit the four (4) shell script (bash) files you have created in a zipped folder with the following namingformat:[surname]_[student-ID]_CSP2101_PF1.zipEND OF ASSIGNMENT BRIEF

QUALITY: 100% ORIGINAL PAPER – NO PLAGIARISM – CUSTOM PAPER

Leave a Reply

Your email address will not be published. Required fields are marked *