Scripting Languages Portfolio Task 2 Assessment Answer

pages Pages: 4word Words: 890

Question :

Scripting Languages: Portfolio Task 2

Task 1 (5 marks)

Write a script that employs a c-style loop to calculate the sum of two assignment scores as they appear ordinally in separate arrays. The arrays are as follows:

First Array
12 18 20 10 12 16 15 19 8 11
Second Array
22 29 30 20 18 24 25 26 29 30

For example, the first two assignment scores to be added would be 12 and 22. The output to the screen of the results should be as follows:

Student_1 Result: xx Student_2 Result: xx Student_3 Result: xx Student_4 Result: xx Student_5 Result: xx Student_6 Result: xx Student_7 Result: xx Student_8 Result: xx Student_9 Result: xx Student_10 Result: xx

…where xx represents the sum of the two corresponding assignment scores in each array.

Requirements

  • Call the script addarray.sh
  • The numbers and their sequence in the array are not to be changed
  • In your script name the first array ass1 and the second array ass2
  • Do not add any of the values in the array in their raw form; only variables may be used in calculations
  • Make sure the output to terminal is neatly aligned in columns

Task 2 (5 marks)

Write a script that retrieves the following information about a file:

  1. Its size in kilobytes
  2. The number of words it contains
  3. The date/time it was last modified

Requirements

  • Call the script fscheck.sh
  • All code involved in retrieving this information from a specified file is to be contained within a function named getprop()
  • Your script will prompt the user for a file name to check, which will then be handed to the getprop() function, i.e. getprop [file_name]
  • The getprop() function’s output is to be a message to terminal that states “The file [file_name] contains [word_count] words and is [file_size]K in size and was last modified [last_modified_date]
  • The last modified date is to be formatted as dd-mm-yy hh-mm-ss, e.g. 16-07-2020 09:59:44
  • Position the getprop() function within the fscheck.sh file and not in a separate file
  • When your tutor runs your script, a .txt file containing a few paragraphs of text will be used to test your script. The file the tutor uses will be located in the same directory as your script is run so there is no need to account for the file’s path.

Task 3 (5 marks)

Write a script that uses grepsed and awk in combination to extract specific information from a .html file and echo it to the terminal as a formatted summary.

Requirements

  • Call the script genrep.sh
  • The script will extract the required data from the file named attacks.html (provided)
  • The output of the script is to display each attack type and the total number of such attacks that took place in a given three (3) month period (see image below):

 output of the script 1

  • Use piping to keep the lines of code required to achieve the outcome to a minimum
  • You will be graded on your use of grepsed and awk to achieve the required outcome, so refrain from using other methods to achieve the result, e.g. using an IFS read within a for or while loop, for which no marks will be awarded
  • To assist you in writing this script, an attacks.html file (in the reqfiles.zip folder provided) has been supplied with sample values. Please note that your tutor will use a file with the same name and structure as the attacks.html file provided, but containing different data. Do not therefore hard- code any of the values within the attacks.html file provided.
  • When your tutor marks your script, the attacks.html file used will be located in the same directory as your script when marked. There is no need therefore to prompt for the location of attacks.html as part of your script.

Task 4 (5 marks)

Write a script that uses awk exclusively to check all user passwords in a text file to ensure they meet the following password strength rules:

  1. Must be eight (8) or more characters in length
  2. Must contain at least one (1) number
  3. Must contain at least one (1) uppercase letter

Requirements

  • Call the script checkpw.sh
  • The script will check all passwords in a file named usrpwords.txt (provided)
  • The output of the script is to display each password with a message that states whether or not it meets password strength requirements (see image below): output of the script 2
  • The first line of the usrpwords.txt file contains header information and must be skipped
  • You will be graded on your use of awk to achieve the required outcome, so refrain from using any other means by which to achieve the result for which no marks will be awarded
  • To assist you in writing this script, a usrpwords.txt file has been supplied (in the reqfiles.zip folder provided) with sample values. Please note that your tutor will use a file with the same name and structure as the usrpwords.txt file provided, but containing different data. Do not therefore hard- code any of the values within the usrpwords.txt file provided.
  • When your tutor marks your script, the usrpwords.txt file used will be located in the same directory as your script when marked. There is no need therefore to prompt for the location of usrpwords.txt as part of your script.
Show More

Answer :

For solution, connect with our online professionals.