HW9 - Shell Scripting (2 points)

Due Friday 08/19 at 10:00 am. No late submissions accepted.

Specification: Spec


wget https://courses.cs.washington.edu/courses/cse391/21sp/homework/hw9/hw9.tar.gz
tar -xzf hw9.tar.gz

Overview

This assignment focuses on Bash shell scripting. Electronically turn in file autograder.sh as described in this document. You will also want the support files from the Homework page on the course web site.

For this assignment, you will write a script autograder.sh that “grades” solutions to a hypothetical homework assignment. You’re given a set of students’ solution files, each of which is supposed to be named task1.sh (though some students used the wrong file name…), and your script will run each of them one at a time, examining the output to see if it matches the expected output. The output from a run of your program will look like this (the first line is the shell prompt):

$ ./autograder.sh 50
Autograding CSE 391 Homework
Grading with a max score of 50

Processing hschafer ...
hschafer has correct output
hschafer has earned a score of 50 / 50

Processing dravir ...
dravir has incorrect output (1 lines do not match)
dravir has earned a score of 38 / 50

Processing joeblow ...
joeblow has incorrect output (4 lines do not match)
joeblow has earned a score of 30 / 50

Processing oterod ...
oterod did not turn in the assignment

To get started, download the hw9.tar.gz from the course web site which should contain the following:

  • students/: This directory contains a set of fake student solutions to examine. Within the students directory there are student folders and files such as:

    students/hschafer/task1.sh
    students/oterod/TAsk1.sh
    students/zorahf/task1.sh
    

    Each student’s directory is supposed to contain a file representing that student’s homework solution (though some students have not turned in the file properly, so it may not exist or may have the wrong name).

    Note that you are not targeting the specific students shown above; your code should not specifically mention names like zorahf or hschafer. Your code should process all students in the students directory.

  • expected.txt: This file contains the expected homework output. This is the text you’ll compare to each student’s output to see whether it is correct.

You will write a script autograder.sh that gives each student a score on the assignment. Your program should accept the maximum score as a command-line argument. For example, to run it with a max score of 50 points, you would type:

$ ./autograder.sh 50

If the user does not pass a value for the maximum points, your script should print the following error message and exit:

$ ./autograder.sh
Usage: ./autograder.sh MAXPOINTS

You do not need to check this argument for validity. If an argument is passed, you may assume it is a positive integer.

Processing Each Student

If your script is passed an argument, it should assume that the current directory contains

  1. a students/ directory whose contents resemble those in the sample files you have been given (containing one directory per student, each named with the student’s id)
  2. and expected.txt

Your script will examine each student in the students/ folder as follows:

  • Run the student’s task1.sh file, using the student’s folder as the working directory. (You may want to capture the student’s output into a file.) Note that the student script files may not have execute permission, so you should manually invoke bash to run them, such as: bash ./task1.sh
  • Compare the student’s output against the expected output file using diff. Run diff so that it ignores all white space (explore the options for diff in the man pages). Count the number of lines that do not match.

    To simplify things, we will consider any line of diff output containing a < or a > to count as 1 line of unmatched content. Produce output in this format:

    hschafer has correct output
    

    or:

    smith has incorrect output (8 lines do not match)
    

    For each unmatched line, deduct 5 points from the student’s score. For example, if the diff output has 4 lines that have < or >, the student should lose 20 points. If the student loses more points than there are points in the assignment, the student should receive 0 points.

    Hint

    You can look for each of < and > separately and total them, or search for lines that have either one.

  • Output each student’s score on the assignment. If a student jones has no differing lines of output, the score output for that student would be:

    jones has earned a score of 50 / 50
    

    If student davis has 3 differing lines of output (-15), the score output would be:

    davis has earned a score of 35 / 50
    

If the student did not turn in the program or incorrectly named the file, the student gets 0 points on the assignment. (See the various if tests from lecture such as -d, -e, etc. to see whether files exist or have various properties.) If the user lewis did not turn in a proper task1.sh file, you would output the following:

lewis did not turn in the assignment

You may assume that no student’s program tries to do anything evil to your computer, such as erasing all your files. You may also assume that students’ code will not lock up and get stuck in any sort of infinite loop. It is okay if your autograder.sh script creates temporary files while doing its work, though if so, you should remove them as you go along.

Development Strategy

  • Make your script print the introduction with the max points command line argument.
  • Make your script able to simply output the names of all of the students to be processed.
  • Make your script able to simply run each student’s task1.sh program and show its output on the terminal.
  • Make your script able to diff the expected output against each student’s task1.sh output.
  • Make your script compute and print the score for each student.
  • Make your print the suggested usage and exit when an argument is not passed for the max points.

Hints

  • Some tasks in your script will involve running Unix commands and capturing their output with $( ). Since such commands run silently as their output is being captured, consider simply running the command first to see that the command is running properly and producing results that you expect.
  • Remember to use echo statements to output partial results, computations, commands, etc. to verify them.

Your script should work if placed in any directory containing expected.txt and a students/ directory. Do not hard code in a specific directory on your machine or your home directory on attu. This is important for grading!! Each Linux/Unix box can be slightly different; for full credit, your commands must be able to work properly on any of the CSE virtual machine image, attu, on the CSE basement lab computers, or Gradescope.