Question

Bash script Suppose you are working as a prof or TA and your students have an...

Bash script

Suppose you are working as a prof or TA and your students have an assignment which requires them each to hand in exactly one file. You've got a directory with all of the submitted files in it, and no other files. You're also lucky enough to have a script that will do all the work of marking a submission; it will take the name of a submission file as its only parameter and will print out a single upper-case letter (A, B, C, D or F) as its only output.

You'd like to know the distribution of marks in your class. Write a bash script called gradeDist.sh (the ".sh" extension is required!) that will take two parameters:

  1. The name of your marking script
  2. The name of the folder containing the assignment submission files

Your gradeDist.sh script must call the marking script to mark each file inside the folder and print a report showing the number of files earning each of the letter grades. If there are sub-folders inside the folder, your script must ignore them (and all of the files inside them). The only output of your gradeDist.sh script should be a list of how many submission files received each of the five possible marks.

Homework Answers

Answer #1

File: gradeDist.sh

#!/bin/bash

# $1 will have the marking script
MARKING_SCRIPT=$1
# $2 will have the assignment submission folder
ASSIGNMENT_SUBMISSION_FILES_DIR=$2

# Declare variables for maintaining the counts of
# submissions of each grade
SUBMISSIONS_A=0
SUBMISSIONS_B=0
SUBMISSIONS_C=0
SUBMISSIONS_D=0
SUBMISSIONS_F=0

# loop through all the files in the supplied directory
for file in "$ASSIGNMENT_SUBMISSION_FILES_DIR"/*
do
  # check if the current location being looped on 
  # is a file or not. 
  if [ ! -d "$file" ]; then
        # Invoke the supllied grading script to grade the 
        # submission. 
        GRADE=`./$MARKING_SCRIPT $file`

        # As per the grade of the submission increment 
        # the count of the respective grade counts.
        if [[ $GRADE == 'A' ]];then
            SUBMISSIONS_A=$(( SUBMISSIONS_A + 1 ))
        elif [[ $GRADE == 'B' ]];then
            SUBMISSIONS_B=$(( SUBMISSIONS_B + 1 ))
        elif [[ $GRADE == 'C' ]];then
            SUBMISSIONS_C=$(( SUBMISSIONS_C + 1 )) 
        elif [[ $GRADE == 'D' ]];then
            SUBMISSIONS_D=$(( SUBMISSIONS_D + 1 ))
        elif [[ $GRADE == 'F' ]];then
            SUBMISSIONS_F=$((SUBMISSIONS_F+1))
        fi
  fi
done
echo "-----------------------------"
echo "GRADE | NUMBER OF SUBMISSIONS"
echo "-----------------------------"
echo "A     |    $SUBMISSIONS_A"
echo "B     |    $SUBMISSIONS_B"
echo "C     |    $SUBMISSIONS_C"
echo "D     |    $SUBMISSIONS_D"
echo "F     |    $SUBMISSIONS_F"
echo "-----------------------------"

How to run:

./gradeDist.sh {GRADING_SCRIPT} {ASSIGNMENT_DIR}
where GRADING_SCRIPT is the script that is used to grade the grade the submissions
and ASSIGNMENT_DIR is the directory where the assigments are there.

Example: ./gradeDist.sh test.sh folder

To test the script
1. I wrote a grading file that would randomly grade the file (test.sh):

#!/bin/bash
RANDOM_NUM=$RANDOM
RANDOM_NUM=$((RANDOM%5))
if [[ $RANDOM_NUM == 0 ]]; then
echo 'A'
elif [[ $RANDOM_NUM == 1 ]]; then
echo 'B'
elif [[ $RANDOM_NUM == 2 ]]; then
echo 'C'
elif [[ $RANDOM_NUM == 3 ]]; then
echo 'D'
elif [[ $RANDOM_NUM == 4 ]]; then
echo 'F'
fi

2. I created a folder named "folder" with random files

3. Then I ran ./gradeDist.sh test.sh folder

Output of the script :

akashpanda@DESKTOP-J1T11IR:/$ ./gradeDist.sh test.sh folder/
-----------------------------
GRADE | NUMBER OF SUBMISSIONS
-----------------------------
A     |    2
B     |    4
C     |    2
D     |    2
F     |    4
-----------------------------
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
NOTE: I just need the answer for question 5 and 6. I already knew the question...
NOTE: I just need the answer for question 5 and 6. I already knew the question 1-4, and wrote down all the requirements for clarification. In this assignment, you are required to write a Bash script, call it assignment2.sh. Your Bash script has to accept at least four input arguments, and must: 1) Print to the user a set of instructions explaining how the PATH variable can be used in Bash. 2) Save the manual of the 'awk' command in...
Question I This question carries 20% of the marks for this assignment. You are asked to...
Question I This question carries 20% of the marks for this assignment. You are asked to develop a set of bash shell script: Write a script that asks for the user's salary per month. If it is less or equals to 800, print a message saying that you need to get another job to increase your income, what you earn is the Minim living cost. If the user's salary is higher than 800 and below 2000, print a message telling...
PLEASE DO QUICK LINUX ASSIGNMENT PLEASE ILL THUMBS UP You need to paste the command and...
PLEASE DO QUICK LINUX ASSIGNMENT PLEASE ILL THUMBS UP You need to paste the command and the output in a word document and submit it. Part1: 1. Log in to Linux using your user account name and password. 2. If you logged in using a graphical login screen, open a terminal window by clicking on the icon in the lower left corner of the desktop to open the main menu, then selecting System Tools, then Terminal. A terminal window opens....
Save your select statements as a script. Place the semicolon at the end of each SQL...
Save your select statements as a script. Place the semicolon at the end of each SQL statement. Please number your select statements from 1 to 8 in your script and comment out each number. Include your name and student number as a comment at the top of your script. The name of the script has to be Assignment1_JohnSmith. Instead of JohnSmith use your First Name and Last Name. Upload your script trough Blackboard. Use SQL Developer to create the My...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total...
C Program Write a program to count the frequency of each alphabet letter (A-Z a-z, total 52 case sensitive) and five special characters (‘.’, ‘,’, ‘:’, ‘;’ and ‘!’) in all the .txt files under a given directory. The program should include a header count.h, alphabetcount.c to count the frequency of alphabet letters; and specialcharcount.c to count the frequency of special characters. Please only add code to where it says //ADDCODEHERE and keep function names the same. I have also...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this...
Please answer in JAVA IDS 401 Assignment 4 Deadline In order to receive full credit, this assignment must be submitted by the deadline on Blackboard. Submitting your assignment early is recommended, in case problems arise with the submission process. Late submissions will be accepted (but penalized 10pts for each day late) up to one week after the submission deadline. After that, assignments will not be accepted. Assignment The object of this assignment is to construct a mini-banking system that helps...
This assignment involves using a binary search tree (BST) to keep track of all words in...
This assignment involves using a binary search tree (BST) to keep track of all words in a text document. It produces a cross-reference, or a concordance. This is very much like assignment 4, except that you must use a different data structure. You may use some of the code you wrote for that assignment, such as input parsing, for this one. Remember that in a binary search tree, the value to the left of the root is less than the...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads data from a file and performs regression analysis using polyfit and polyval. The function shall have the following features: The input arguments shall include the file name (string), a vector of integers for the degrees of polynomial fits to be determined, and an optional plot type specifier (‘m’ for multiple plots, ‘s’ for a single plot - default). The data files will be text...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in...
Part A. Input Validation (Name your C program yourLastName_yourFirstName_Lab4a.c) 1. Place the code you developed in Lab 2 to obtain a diameter value from the user and compute the volume of a sphere (we assumed that to be the shape of a balloon) in a new program, and implement the following restriction on the user’s input: the user should enter a value for the diameter which is at least 8 inches but not larger than 60 inches. Using an if-else...