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
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...
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...
Bash script with branching and looping Part 1: 1. Create a variable called NAME and set...
Bash script with branching and looping Part 1: 1. Create a variable called NAME and set it equal to the empty string (NAME=””). Create a variable called NAME_LENGTH and set it equal to the length of your last name. Output the value of the NAME variable to show that it is empty. 2. Write a FOR loop that executes as many times as there are letters in your name (use the NAME_LENGTH variable in your condition). Use a CASE statement...
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...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of...
Subject: Shell Scripting Practice A File: practice-script-a Create File practice-script-a that: 1. Accepts any number of userids on the command line 2. For each userid, display the userid, PID, CPU time, and current command for each process owned by that userid Your output should look similar to this example: practice-script-a doug.jones User: doug.jones PID: 8748 TIME: 00:00:00 COMMAND: /usr/lib/systemd/systemd --user User: doug.jones PID: 8749 TIME: 00:00:00 COMMAND: (sd-pam)    User: doug.jones PID: 8750 TIME: 00:00:00 COMMAND: sshd: doug.jones@pts/5 User: doug.jones...
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....
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may...
PYTHON : Create a Email Address Parser (* Please do make comments*) Often times, you may be given a list of raw email addresses and be asked to generate meaningful information from such a list. This project involves parsing such a list and generating names and summary information from that list. The script, eparser.py, should: Open the file specified as the first argument to the script (see below) Read the file one line at a time (i.e., for line in...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you will demonstrate how to create an HTML file, externally link a JavaScript file, and write some source code in the JavaScript file. a..Create two blank files to be an HTML file and a JavaScript file. The file names should be partA.html and partA.js. b.. Create a basic HTML webpage structure. c..Link the JavaScript file to the HTML file using the <script> tag. d.. Prompt...
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...
C++ Programming   You are to develop a program to read Baseball player statistics from an input...
C++ Programming   You are to develop a program to read Baseball player statistics from an input file. Each player should bestored in a Player object. Therefore, you need to define the Player class. Each player will have a firstname, last name, a position (strings) and a batting average (floating point number). Your class needs to provide all the methods needed to read, write, initialize the object. Your data needs to be stored in an array of player objects. The maximum...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT