0% found this document useful (0 votes)
3 views10 pages

Assignment

The document outlines a Bash scripting assignment for organizing and executing student algorithm submissions at an engineering university. It consists of two main tasks: organizing code files by type and student ID, and executing the codes with test cases while generating a CSV report of the results. The assignment includes specific requirements for file naming, directory structure, and command-line arguments, along with a deadline for submission.

Uploaded by

mrahman191110
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

Assignment

The document outlines a Bash scripting assignment for organizing and executing student algorithm submissions at an engineering university. It consists of two main tasks: organizing code files by type and student ID, and executing the codes with test cases while generating a CSV report of the results. The assignment includes specific requirements for file naming, directory structure, and command-line arguments, along with a deadline for submission.

Uploaded by

mrahman191110
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

United International University

CSE 4510: Operating Systems Laboratory


Bash Scripting Assignment

1. Overview

Suppose you have recently joined as a teacher at an engineering university. You are in charge of evaluating an Algorithm assignment that
students have submitted via elms. After downloading the submission files, you are in awe! No matter how many times you have reminded them
to submit their files following a standard, some students paid no attention to that. Now you have to organize the submissions and execute them.
Luckily, you are an expert in bash scripting. You will use your expertise to automate these tasks and save your precious time.

Your assignment has two parts.


A. Organize the code file into directories by file types and student ID.
B. Execute the codes with test cases and match them with the expected results.

You will be provided with


1. Submission folder (submissions)
2. Test case folder (tests)
3. Answer folder (answers)
2. Task A: Organize

Inside the submissions folder, there will be multiple zipped files – one zipped file for each student (see the helping materials section to unzip).
Inside the zipped file are the files submitted by the student. The name of the zipped file will be in the following format:

<Full Name>_<7 digit serial number>_assignsubmission_file_<9 digit student id>.zip

Students will submit codes in C (.c extension), Python (.py extension), and Java (.java extension). It is guaranteed that one student has
submitted only one code file, either in C or Python or Java. There may be other files ending in different extensions. You have to ignore those
extra files. The code file of a student can be located inside any directory/subdirectory of the zipped file of the student.

You have to create a new target directory (targets). Inside the target directory, there will be three subdirectories - C, Python, Java.

Suppose, student 011212XXX has written his/her code in C. You have to create a new subdirectory inside <target
directory>/C/011212XXX and copy the C file inside <target directory>/C/011212XXX and rename it to main.c.

Suppose, student 011212XXX has written his/her code in Java. You have to create a new subdirectory inside <target
directory>/Java/011212XXX and copy the .java file inside <target directory>/Java/011212XXX and rename it to [Link].

Suppose, student 011212XXX has written his/her code in Python. You have to create a new subdirectory inside
<target directory>/Python/011212XXX and copy the .py file inside <target directory>/Python/011212XXX and rename it to [Link].

Refer to the Match/targets directory that has been provided to better understand the task.

3. Task B: Execute and Match

Inside the test case folder (tests), test cases are stored in the pattern of [Link], [Link], …, [Link] and so on. They are guaranteed to
follow such naming conventions.
For each test file, there will also be an accepted answer file inside the answer folder (answers), stored in the pattern of [Link], [Link], …,
[Link] and so on. They are also guaranteed to follow such naming conventions.

Your task is to compile and run the codes you have organized. Note that Python codes do not require compiling. Refer to the helping materials
section to compile and run the code files.

For a C file, the compiled executable file must be named as [Link]


For a Java file, the compiled class file must be named as [Link]

You have to store the output files of each test case inside the student’s folder inside the organized target folder. The output files will follow the
naming convention of [Link], [Link], …, [Link] and so on.

Then, you will match the output files with the corresponding answer files using the command diff. If there are any mismatches between an
output file and an answer file, it will be considered as a failure in that test case.

Finally you have to generate a CSV file (inside <target directory>, named [Link]) having columns, student_id, type, matched,
not_matched. For each student you have to record his/her student ID, his/her programming language (C/Python/Java), number of test cases
matched and number of test cases that did not match.

Tentative Algorithm: (obviously, there are rooms for improvement in this algorithm)
For each student
Find the code file type (C/Python/Java)
Compile if needed
For each test cases test<i>.txt
Run the code file
Store the output in out<i>.txt
Match out<i>.txt with corresponding ans<i>.txt file
Record how many test cases matched, how many not matched
Generate a CSV file <target directory>/[Link]
4. Example

Download the “[Link]” file from elms. After unzipping it, you will find two folders and the following
subdirectories.

➔ Workspace
◆ submissions # submission folder
◆ tests # test input folder
● [Link]
● [Link]
● …
● [Link]
◆ answers # accepted output folder
● [Link]
● [Link]
● …
● [Link]

➔ Match
◆ targets # this will not be provided during evaluation
● C # student who submitted C code
○ 011212096
◆ main.c
◆ [Link]
◆ [Link]
◆ …
◆ [Link]
○ 011212097
○ …
● Python # student who submitted Python code
○ 011223045
◆ [Link]
◆ [Link]
◆ …
◆ [Link]
○ …
● Java # student who submitted Java code
○ 011223075
◆ [Link]
◆ [Link]
◆ [Link]
◆ …
◆ [Link]
○ …
● [Link] # result of each student

The Workspace/submissions folder consists of zipped files of individual students.

You aim to write a shell script ([Link]) that will be executed inside the Workspace directory. The script will take 4 mandatory arguments
and 1 optional argument.

Mandatory Arguments (In Order):


1. Path of submission folder
2. Path of target folder (create target folder if it does not exist)
3. Path of test folder
4. Path of answer folder

Optional Argument (In Order):


1. -noexecute
a. If provided, will not not perform Task B.
b. Note that, with this switch, no output files and executable files will be generated.

Sample commands:

user@machine:~/Offline/Workspace$ ./[Link] submissions targets tests answers

After executing the [Link] file, it will generate a new folder inside the Workspace directory named targets. Your script must generate
Workspace/targets identical to the Match/targets directory.

user@machine:~/Offline/Workspace$ ./[Link] submissions targets tests answers -noexecute

user@machine:~/Offline/Workspace$ ./[Link] submissions targets tests answers

5. Additional Information
● Each Java file is guaranteed to have Main as the main class.
● Each code is guaranteed to compile and run without error/exception.
● You must generate a CSV file following the exact format that is provided. Order of student ID does not matter. The names of the
columns must match.
● You must generate executable files, output files following the format. The evaluation will be done by a script and failure to follow the
format will result in a penalty.
● If the number of arguments is less than the required number, you must print a usage message showing how to use the script.
6. Helping Materials

Unzipping
● Use the command unzip to unzip files.
● Use -d switch to unzip to a specific folder.
● Refer to the man unzip for more.
● Test the command in the terminal before using it inside the script.

Substring Extraction by Pattern


● Run the following commands in a script and see what happens.

string=[Link]
echo ${string%.world}

Substring Extraction by Index


● Run the following commands in a script and see what happens.

string=[Link]
echo ${string:2:1}
echo ${string:2:2}
echo ${string:2:20}
echo ${string: -1} # mind the space before - sign
echo ${string: -4}
echo ${string:2: -1}

Difference between the Two Files


● Use the command diff to check if the two files are the same.
● Refer to the man diff for more.
● Test the command in the terminal before using it inside the script.
Arrays
● Run the following commands in a script and see what happens.

array=("apple" "mango" "orange")


i=0
echo ${array[$i]}
i=2
echo ${array[$i]}

Run a C File
● gcc file_name.c -o executable_name
● ./executable_name

Run a Python Script


● python3 file_name.py

Run a Java File


● javac file_path.java
● This will create a .class file at the same directory as the .java file
● java -cp <directory_of_the_java_file> <name_of_main_class>

Kill a Running Script from Inside the Script


● kill -INT $$

7. Marks Distribution

Tasks Sub Task Marks

Task A Organize Files by Type & ID 20


Ignore other files 5

Task B Compile & Run Files 20

Match Outputs 10

Generate CSV 10

Target folder matches the specified format exactly 10

Command line argument (Mandatory Arguments) 5

-noexecute No Execute 10

Usage Message 5

Submission matches format (Section 8) 5

Total 100

8. Submission

● Create a directory by your 9 or 10 digit student id (011XXXXXX).


● Put your [Link] file inside.
● Zip the folder, rename it to [Link].
● Submit the zipped folder.

Deadline: 5 September, 2025. 11:55 PM.


9. Plagiarism Policy

● –100% marks will be deducted for plagiarism.


● Work on the problem on your own.

10. Acknowledgement
 Md. Tareq Mahmood
 Assistant Professor, dept of CSE, BUET.

You might also like