For this assignment, you will use bash create a simple course catalog for administrators to update
the details of each course offered by their department. The system will store basic information about
each course, allowing the user to create, read, update, and delete them.
This assignment requires only the utilities used so far in the lecture notes. Do not use sed, awk,
or any programming languages or utilities not yet covered in the lecture notes.
Tip: Filenames in the native Linux filesystem are case-sensitive. Thus, without proper consideration, a course whose associated filename was created as cs3423.crs (based on lowercase input
given for the course’s department code the time of its creation) will not also be associated with the
file CS3423.crs. This is not desirable behavior, however, as user’s may unexpectedly enter either
uppercase or lowercase department codes when using your script.
Therefore, you may utilize a bash feature (known as “case modification” parameter expansion)
that enables you to easily convert the contents of a variable to its uppercase equivalent. For example,
this feature can be utilized to produce the capitalized contents of the variable containing a department code by simply writing ${dept_codeˆˆ} instead of $dept_code when building the filename
you will use for a particular course.
Tip: Note, that when prompted to enter a department code and course number, you should enter
these values as two separate tokens separated by a space. Otherwise, it would be necessary to perform
complex token-splitting to separate these values, which is outside the scope of this assignment. For
example, when prompting the user:
Enter a department code and course number:
You should enter “cs 3423”, not “cs3423”!
Storing Course Information
Course information will be stored in text files.
1. Files will be stored inside a directory called data within the same directory as your script.
2. Each file will be named based on the combination of a department code and a course number,
which consists of two or three letters followed by an integer with exactly four digits, followed
by the extension .crs (notice that the text file does not end in .txt. Does that need to be
accounted for?).
3. A course file consists of exactly five lines:
• dept_code (two or three letter abbreviation) dept_name (string with probable whitespace)
• course_name (string with probable whitespace)
Assignment 1: Shell Scripting Page 1 of 6
• course_sched (string consisting precisely of either “MWF” or “TH”) course_start (string
with no whitespace) course_end (string with no whitespace)
• course_hours (credit hours, unsigned integer)
• course_size (enrolled students, unsigned integer)
* Department names may contain whitespace. You should account for names with multiple
tokens (e.g., “ESL English as a Second Language” =⇒ dept_code = “ESL”, and dept_name
= “English as a Second Language”)
4. Example file named esl3053.crs
ESL English as a Second Language
Literacy in a Second Language
MWF 8/26/19 12/13/19
3
52
Script Execution
When the script is run, the following should occur. All script output should appear exactly as it
appears below.
1. Upon running your script, the user should be presented with the following menu:
Enter one of the following actions or press CTRL-D to exit.
C – create a new course record
R – read an existing course record
U – update an existing course record
D – delete an existing course record
E – update enrolled student count of existing course
T – show total course count
2. The user then enters a one-character action (upper or lowercase), leading to one of the following.
• C: a course is created
(a) From the terminal, read the following one at a time:
i. Department code (two-to-three character string)
ii. Department name (string possibly containing whitespace)
iii. Course number (integer)
iv. Course name (string possibly containing whitespace)
v. Course schedule (string ∈ {MWF,TH})
vi. Course start date (string with slashes)
vii. Course end date (string with slashes)
Assignment 1: Shell Scripting Page 2 of 6
viii. Course credit hours (unsigned integer)
ix. Initial course enrollment (unsigned integer)
(b) Using the values entered by the user, create a new file in the data folder based on
the instructions above.
(c) Update data/queries.log by adding the following line:
[date] CREATED: dept_code course_num course_name
where date is the output from the date command and dept_code, course_num, and
course_name are the corresponding values.
(d) If the course already exists, print the following error and continue with the script.
The script should accept all seven inputs before checking if the record exists.
ERROR: course already exists
• R: read an existing course’s information
(a) Prompt the user for a course department and course number: (e.g., “cs 3423”)
Enter a department code and course number:
(b) Search for the specified course using the provided department and number (e.g., “cs
3423”).
(c) Print the course information in the following format:
Course department: dept_code dept_name
Course number: course_num
Course name: course_name
Scheduled days: course_sched
Course start: course_start
Course end: course_end
Credit hours: course_hours
Enrolled Students: course_size
(d) If the course is not found, print the following error instead and continue with the
script.
ERROR: course not found
• U: update an existing course record
(a) Prompt the user for the following one at a time:
i. Department code (two-to-three character string)
ii. Department name (string possibly containing whitespace)
iii. Course number (integer)
iv. Course name (string possibly containing whitespace)
v. Course meeting days (string ∈ {MWF,TH})
vi. Course start date (string with slashes)
vii. Course end date (string with slashes)
Assignment 1: Shell Scripting Page 3 of 6
viii. Course credit hours (unsigned integer)
ix. Course enrollment (unsigned integer)
(b) Search for the specified course using the course department and course number (e.g.,
“cs 3423”).
(c) Update each of the corresponding fields based on the user input. If the user input
is blank for a particular field, keep the original value from the file.
(d) Update data/queries.log by adding the following line:
[date] UPDATED: dept_code course_num course_name
where date is the output from the date command and dept_code, course_num, and
course_name are the corresponding values.
(e) If the course is not found, print the following error and continue with the script. The
script should accept all nine inputs before checking if the record exists.
ERROR: course not found
• D: delete an existing course
(a) Prompt the user for a string representing the course department and number (e.g.,
“cs 3423”):
Enter a course department code and number:
(b) Delete the specified course’s file.
(c) Update data/queries.log by adding the following line:
[date] DELETED: dept_code course_num course_name
where date is the output from the date command and dept_code, course_num, and
course_name are the corresponding values.
(d) Print the following message to stdout with the course’s number:
course number was successfully deleted.
(e) If the course is not found, print the following error instead and continue with the
script.
ERROR: course not found
• E: update the number of enrolled students for an existing course
(a) Prompt the user for a string representing the course department and number (e.g.,
“cs 3423”):
Enter a course department code and number:
(b) Prompt the user for an enrollment change amount (e.g., entering a value of 3 would
represent enrolling three new students in the class, while -2 would reflect two students
having dropped the course):
Enter an enrollment change amount:
(c) Search for the specified course using the course number.
(d) Update the course record by adding the new enrollment count to the course’s current
enrollment count. Negative values are allowed. (i.e., students could drop the
Assignment 1: Shell Scripting Page 4 of 6
class).
(e) Update data/queries.log by adding the following line:
[date] ENROLLMENT: dept_code course_num course_name
changed by change_amt
where date is the output from the date command and dept_code, course_num,
course_name, and change_amt are the corresponding values.
(f) If the course record is not found, print the following error and continue with the
script. The script should accept the enrollment change amount before checking if
the record exists.
ERROR: course not found
• T: print the total number of course records
(a) Print the total number of .crs files within the data directory:
Total course records: total
where total is the total .crs files.
• If an invalid character is entered, print the following error and continue with the script.
ERROR: invalid option
3. After an action is completed, display the menu again. This should go on indefinitely until
CTRL-D or the end of a file is reached.
Assignment Data
An initial data set can be found in /usr/local/courses/ssilvestro/cs3423/Fall19/assign1.
Copy this to your own assignment’s directory.
Script Files
Your program should consist of seven bash files with the following names (case sensitive):
• assign1.bash – the main file which is initially invoked
• create.bash – logic for the create option
• read.bash – logic for the read option
• update.bash – logic for the update option
• delete.bash – logic for the delete option
• enroll.bash – logic for the update enrollment option
• total.bash – logic for the total option
Assignment 1: Shell Scripting Page 5 of 6
Verifying Your Program
Your program must work with the input provided in a1Input.txt. To test it:
1. Verify that your assignment folder has a data directory with the initial data set.
2. Execute your script and redirect a1Input.txt into it. You should not be copying or typing
the contents of a1Input.txt into your terminal. Redirection must work.
3. Verify that the output and files are as expected.
Submission
Turn your assignment in via Blackboard. Your zip file, named abc123.zip (with your personal
abc123) should contain only your seven bash files.
For this assignment, you will use sed, bash, and the other utilities you have used in class to create a program for use by a municipality for both redacting sensitive information from internal communications, as well as simplifying and standardizing the format of these documents prior to their release and circulation. Your program should take the names of one or more files that are to be redacted as command line arguments. This assignment requires only sed, bash, and the other utilities used so far in class. Do not use awk, Python, or any other languages/utilities. Redaction and Substitution Rules For all files specified, the following changes should be made in place. No other changes should be made to the file. • Driver’s License numbers begin with xx DL, where xx is a two-letter state code identifying the origin of the issuing state. Following this code is a space character, then a license number composed of at least 6 digits in length. For example, the following are all valid driver’s license numbers: – TXDL 12345678 – VADL 123456 – WADL 1234567890 These numbers should be redacted by simply replacing the license number with a sequence of six X characters. • Credit Card Numbers Credit card numbers must be redacted, but it is desirable that the censored text still retain information suitable for the identification of both the type of card (i.e., the issuer), as well as its last four digits. Each card network specifies a unique first digit to the cards they issue, and typically contain 16 digits in total. American Express is an exception to this, in which the second number can only be a 4 or a 7, and the total number of digits is only 15. In summary: – Visa cards: Begin with a 4 and have 16 digits – Master Cards: Begin with a 5 and have 16 digits – American Express cards: Begin with a 3, followed by a 4 or a 7, and have 15 digits – Discover cards: Begin with a 6 and have 16 digits Card number data should be redacted as in the following examples. Note that 16 digit numbers may or may not be separated into groups of four using hyphens – this is optional. Hyphenation of American Express cards into sections of 4, 6, and 5 digits is similarly common, and also optional. Examples of the expected substitutions for each card type are as follows: Assignment 2: sed Page 1 of 4 – 5441-4839-9284-3129 → MC-3129 – 3770-123456-78900 → AMEX-8900 – 6093-2033-0662-5389 → DISC-5389 – 4291723799801302 → VISA-1302 • Texas Vehicle License Plate numbers should be similarly obliterated. Texas vehicle plates appear in one of two formats, but both will be written with the letters TX and an optional space preceding them. The first type is six alphanumeric characters, optionally separated by a hyphen in the middle. The second type begins with three alphabetic characters, followed by four digits, again optionally separated by a hyphen. Examples of valid type one Texas license plate numbers are: – TX 32P9ZP – TX 32P-9ZP – TX32P9ZP – TX32P-9ZP Examples of valid type two Texas license plate numbers are: – TX JTK8791 – TX JTK-8791 – TXJTK8791 – TXJTK-8791 These numbers should be redacted by simply replacing the license plate number with a sequence of six X characters. • Current Date Placeholder The document authors may use the shorthand symbol in order to insert the current date (i.e., today’s date). Regardless of the date on which your script is run, this placeholder should be updated with the correct current date. • Municipality Name Placeholder The authors of these documents may use the shorthand symbol in order to designate the full name of their municipality. Any such references should be replaced with the full name: City of Gainsville, Florida. Example Original redactme.txt: 1 2 Date : 3 T i t l e : Memorandum #139 4 Assignment 2: sed Page 2 of 4 5 Dear s t a f f : 6 7 Memorandum #139 ha s been amended a s f o l l o w s , i n a c c o r d a n c e w i t h t h e 8 u p da te d em pl oyee o p e r a t i o n s and p u r c h a s i n g p o l i c y ∗ : 9 10 The o n l y em pl o y e e s a u t h o r i z e d t o o p e r a t e v e h i c l e #102 ( l i c e n s e p l a t e 11 TX JTK8791 ) , v e h i c l e #162 ( l i c e n s e p l a t e TX 32P−9ZP) , and v e h i c l e #262 12 ( l i c e n s e p l a t e TX AJC−6244) a r e t h o s e em pl o y e e s who p o s s e s s t h e f o l l o w i n g 13 d r i v e r ‘ s l i c e n s e s : 14 15 TXDL 02851332 16 TXDL 00748892 17 VADL 590401 18 FLDL 104281332 19 20 F u r t h e r , u sa g e o f c i t y c r e d i t c a r d s w i l l be s t r i c t l y l i m i t e d t o t h e 21 f o l l o w i n g d e p a r tm e n t a l ca r d s , u n t i l f u r t h e r n o t i c e : 22 23 5441−4839−9284−3129 24 3770−123456−78900 25 6093−2033−0662−5389 26 4291723799801302 27 28 Thank you , 29 Mgmt 30 31 ∗ P o l i c y r e v i s i o n da t e 2/1/13 ( o r i g i n a l l y p a s s e d 7 / 1 3 / 9 2 ) . Redacted Version of redactme.txt: 1 C i t y o f G a i n s v i l l e , F l o r i d a 2 Date : 09/19/2019 3 T i t l e : Memorandum #139 4 5 Dear s t a f f : 6 7 Memorandum #139 ha s been amended a s f o l l o w s , i n a c c o r d a n c e w i t h t h e 8 u p da te d em pl oyee o p e r a t i o n s and p u r c h a s i n g p o l i c y ∗ : 9 10 The o n l y em pl o y e e s a u t h o r i z e d t o o p e r a t e v e h i c l e #102 ( l i c e n s e p l a t e 11 TX XXXXXX) , v e h i c l e #162 ( l i c e n s e p l a t e TX XXXXXX) , and v e h i c l e #262 12 ( l i c e n s e p l a t e TX XXXXXX) a r e t h o s e em pl o y e e s who p o s s e s s t h e f o l l o w i n g 13 d r i v e r ‘ s l i c e n s e s : 14 15 TXDL XXXXXX 16 TXDL XXXXXX 17 VADL XXXXXX 18 FLDL XXXXXX 19 20 F u r t h e r , u sa g e o f c i t y c r e d i t c a r d s w i l l be s t r i c t l y l i m i t e d t o t h e 21 f o l l o w i n g d e p a r tm e n t a l ca r d s , u n t i l f u r t h e r n o t i c e : 22 23 MC−3129 24 AMEX−8900 25 DISC−5389 Assignment 2: sed Page 3 of 4 26 VISA−1302 27 28 Thank you , 29 Mgmt 30 31 ∗ P o l i c y r e v i s i o n da t e 2/1/13 ( o r i g i n a l l y p a s s e d 7 / 1 3 / 9 2 ) . Script Execution Your program should be invoked through a single bash file (see below) with the filename(s) containing the sensitive data as argument(s). Example: $ assign2.bash redactme.txt Assignment Data A sample input file can be found in: /usr/local/courses/ssilvestro/cs3423/Fall19/assign2. When using this data, remember that your will be made to overwrite the files. Be sure to make a backup of the files and restore them every time you run the script. Script Files Your program should consist of exactly two files: • assign2.bash – the main file which is initially invoked • Exactly one .sed file which is used for a sed invocation run in assign2.bash. Verifying Your Program Your program must work for arbitrary files by applying the rules above. You can test your program with the input provided in redactme.txt and compare the output with redacted.txt using diff (check the man-pages on how to use it). You should create your own test cases to test for the recursion feature. Submission Turn your assignment in via Blackboard. Your zip file, named abc123.zip (with your abc123) should contain only your bash and sed files.
Part A
For this part of the assignment, you will create a single command which will take the contents of a
passwd file (usually found in /etc/passwd) and print it in sorted order by the user’s last name (that
is, their surname, not their username). Normally, you could solve this with the following options on
sort: $ sort -t: -k6 /path/to/passwd
You, however, must solve this problem with the utilities covered in class so far. You may (and should)
use sort, but you may not use any of its options (e.g., -k, -t, etc).
Example
Input:
1 lkj293 : x :1539:1543: Albert Einstein :/ home / einstein :/ bin/ bash
2 kkr590 : x :1540:1544: Elvis Presley :/ home / presley :/ bin/ bash
3 nwk409 : x :1541:1545: George Washington :/ home / washington :/ bin/ bash
4 yaa265 : x :1542:1546: Bruce Banner :/ home / banner :/ bin/ bash
5 yhn211 : x :1543:1547: George Harrison :/ home / harrison :/ bin/ bash
6 lfa806 : x :1544:1548: Jane Austen :/ home / austen :/ bin/ bash
7 ilo709 : x :1545:1549: Walt Disney :/ home / disney :/ bin/ bash
8 rfd576 : x :1546:1550: Buzz Aldrin :/ home / aldrin :/ bin/ bash
9 lko889 : x :1547:1551: Marie Curie :/ home / curie :/ bin/ bash
10 cfq219 : x :1548:1552: J . R . R . Tolkien :/ home / tolkien :/ bin/ bash
11 ncz856 : x :1549:1553: Christopher Columbus :/ home / columbus :/ bin/ bash
12 pql747 : x :1550:1554: Julius Caesar :/ home / caesar :/ bin/ bash
Output:
1 rfd576 : x :1546:1550: Buzz Aldrin :/ home / aldrin :/ bin/ bash
2 lfa806 : x :1544:1548: Jane Austen :/ home / austen :/ bin/ bash
3 yaa265 : x :1542:1546: Bruce Banner :/ home / banner :/ bin/ bash
4 pql747 : x :1550:1554: Julius Caesar :/ home / caesar :/ bin/ bash
5 ncz856 : x :1549:1553: Christopher Columbus :/ home / columbus :/ bin/ bash
6 lko889 : x :1547:1551: Marie Curie :/ home / curie :/ bin/ bash
7 ilo709 : x :1545:1549: Walt Disney :/ home / disney :/ bin/ bash
8 lkj293 : x :1539:1543: Albert Einstein :/ home / einstein :/ bin/ bash
9 yhn211 : x :1543:1547: George Harrison :/ home / harrison :/ bin/ bash
10 kkr590 : x :1540:1544: Elvis Presley :/ home / presley :/ bin/ bash
11 cfq219 : x :1548:1552: J . R . R . Tolkien :/ home / tolkien :/ bin/ bash
12 nwk409 : x :1541:1545: George Washington :/ home / washington :/ bin/ bash
Assignment 3: awk Page 1 of 4
Script Execution (Part A)
Since the fox machines do not have useful /etc/passwd files (no first and last names), you will use
the one provided with this assignment. Your submission will include a bash file (assign3A.sh) with
exactly one line in it (you do not need a shebang) and should take the path to the passwd file as
the first argument. Do not include an awk file or any other files besides assign3A.sh.
$ assign3A.sh /path/to/passwd
Part B
For this part of the assignment, you will only use the utilities covered in class so far (primarily awk) to
create a program for printing user process information. Do not use Python or any programs/utilities
not covered in class.
Your program should take the output from ps -ef and print the following for each user having a
username matching the abc123 format:
• Username
• List of commands
After listing statistics for each user, the program should print the following information for all users
having a username matching the abc123 format:
• Line with earliest start time
• Line with latest start time
Do not use sed, Python, or any other languages/utilities not covered in class.
Example
The example below is an excerpt from the ps -ef command which your program should be able to
take as input. Note that if a process began execution on a previous calendar day, its STIME value
will not be in the usual “hours and minutes” format, but rather in “month and day” format. This
should be accounted for properly, and thus a simple text/numerical comparison will not suffice.
Assignment 3: awk Page 2 of 4
Input:
1 UID PID PPID C STIME TTY TIME CMD
2 adz110 5344 5334 0 08:47 pts /2 00:00:00 bash
3 dmq292 6908 6854 0 Jun04 pts /1 00:00:00 bash
4 adz110 7227 7150 0 Jul11 pts /9 00:00:00 who
5 erg474 7466 7461 0 08:54 pts /10 00:00:00 ls
6 dmq292 7966 7960 0 Jun04 pts /13 00:00:00 assign1 . sh if of
7 xle135 8983 8636 0 08:59 pts /15 00:00:00 ssh ctf . cs . utsarr . net
8 zeh458 9057 1980 0 08:59 pts /7 00:00:00 vim prog . c
9 rslavin 9150 9139 0 08:59 pts /16 00:00:00 ps – af
10 xle135 8636 8628 0 08:58 pts /15 00:00:00 bash
Output:
1 User : adz110
2 bash
3 who
4 User : dmq292
5 bash
6 assign1 . sh if of
7 User : erg474
8 ls
9 User : xle135
10 bash
11 ssh ctf . cs . utsarr . net
12 User : zeh458
13 vim prog . c
14
15 Earliest Start Time :
16 dmq292 6908 6854 0 Jun04 pts /1 00:00:00 bash
17
18 Latest Start Time :
19 xle135 8983 8636 0 08:59 pts /15 00:00:00 ssh ctf . cs . utsarr . net
Also, if there is a tie for earliest or latest start times, take the one with the UID that comes first
alphabetically.
Hint: Consider using sort to help with grouping.
Script Execution (Part B)
Your program should each be invoked through a single bash file (see below) with input taken from
stdin. The resulting output should be printed directly to stdout.
$ assign3B.sh < ps.in
or
Assignment 3: awk Page 3 of 4
$ ps -ef | assign3B.sh
Assignment Data
Sample input files can be found in:
/usr/local/courses/ssilvestro/cs3423/Fall19/assign3.
Script Files
Your submission should consist of multiple files:
• assign3A.sh – a bash script with a single line of code (i.e., one command) for part A
• assign3B.sh – a bash script to invoke for part B.
• assign3B.awk – the awk program used in assign3B.awk
Verifying Your Programs
Part A can be tested with the sample input provided with passwd.in.
Part B can be tested with the sample input provided with ps.in. Your program should also work
with arbitrary input from the ps -ef command.
Submission
Turn your assignment in via Blackboard. Your zip file, named abc123.zip with your personal abc123
should contain only your bash and awk files.
For this assignment, you will use awk, sed, and bash to create a simple templating engine. Your
program should take as input a generic template with placeholders for generic data, a set of input
files containing data which should be applied to the template, and a date. Instantiated templates
using the input data will be output to a subdirectory.
This assignment requires only sed, awk, and bash. You may use any combination of these programs
and are not required to use all of them. Do not use Python or any other languages/utilities.
Hint: Since you will need to produce many files from many inputs, it may be useful to use awk to
generate sed and/or bash scripts.
Data Format
Data will be stored in the same format as the data in Assignment 1. For each course with an
enrollment greater than 50, your program will use the provided template to generate an advisory
report specifically for them.
1. Data files (i.e., of the same format as those generated in Assignment 1) will be stored inside
a directory specified by the user.
2. Each file within that directory will be named based on the department code (two or three
uppercase alphabetic characters), a course number (exactly four digits), and ending with an
extension of .crs.
3. A course file consists of exactly five lines:
• dept_code (two or three character string) dept_name (string with possible whitespace)
• course_name (string with possible whitespace)
• course_sched (string: either TH or MWF) course_start (start with no whitespace)
course_end (string with no whitespace)
• credit_hours (integer)
• num_students (integer representing number of enrolled students)
4. Example file named MAT1311.crs
MAT Mathematics
Calculus I
TH 8/26/19 12/11/19
3
62
Assignment 4: More Scripting Page 1 of 4
Templating
Templates will include variable names to be filled in with data using double square brackets. For any
data file of the format described above, each of the variables (including the square brackets) should
be substituted with the data’s actual value. Your program should work for arbitrary templates
using the same variables listed below corresponding to the item values described. More than one
variable may appear per line.
• [[dept_code]]
• [[dept_name]]
• [[course_name]]
• [[course_start]]
• [[course_end]]
• [[credit_hours]]
• [[num_students]]
• [[course_num]] (the course number as specified in the filename of the .crs file)
• [[date]] (see below)
Example Template:*
1 < html >
2 < body >
3 <h1 > NOTICE OF OVERENROLLMENT – COURSE [[ dept_code ]] [[ course_num ]]←-
– [[ date ]] </ h1 >
4 <p >
5 Dear Instructor ,
6 </p >
7 <p >
8 Your course , [[ course_name ]] , scheduled from [[ course_start ]] to←-
[[ course_end ]] , has exceeded normal capacity with an ←-
enrollment of [[ num_students ]] students . This must be ←-
corrected within thirty days or this issue will be referred ←-
to the [[ dept_name ]] department for further review .
9 </p >
10 <p >
11 – Administration
12 </p >
13 </ body >
14 </ html >
* This is only a single example of a single template! You must assume that multiple different
templates, with various combinations of variables, will be ran against your program. Experiment
with exercising your program using your own custom scripts, as none will be provided to you. This
is to emphasize the notion that no single template should be used as a test instrument; your script
will be tested against several unknown-to-you templates.
Assignment 4: More Scripting Page 2 of 4
Date Argument
The third command-line argument should be a date manually entered by the user of the format
MM/DD/YYYY. This value should be substituted anywhere where [[date]] appears.
Output
All output files should be written to the directory defined by the last argument. This directory may
or may not already exist. Each file should be named by the course’s department code and number,
and with the extension .warn.
Script Execution
Your program should be invoked through a single bash file (see below) with four arguments:
data directory, template file, date, and output directory. Assuming the program executes correctly,
no output should be printed to the screen.
$ assign4.sh ./data assign4.template 12/16/2021 ./output
Assignment Data
Sample input files can be found in:
/usr/local/courses/ssilvestro/cs3423/Fall19/assign4.
Script Files
Your program may consist of multiple files:
• assign4.sh – the main file which is initially invoked (required)
• .awk files
• .sed files
Note: If your program generates any intermediate awk or sed files during execution, name them
beginning with the letter ’g’. Moreover, delete them when your program has completed.
Extra Credit (5 points)
Allow your program to take optional fifth and sixth arguments describing the character(s) surrounding the variables instead of double square brackets. This feature should work for the following
characters as either the opening or closing symbol, “/”, “|”, “}”, and “{”. Note that these can be
in any combination (e.g., starting with “{” and ending with “|”) If no fifth and sixth arguments are
passed, the program should behave as normal. You may assume that if a fifth argument is passed,
Assignment 4: More Scripting Page 3 of 4
a sixth will be present, too.
Example:
$ assign4.sh ./data assign4.template 12/16/2021 ./output ’{’ ’|’
The above invocation should replace variables in the template such as {date| instead of [[date]].
Extra credit is not given to late assignments. All requirements must be met to qualify for extra credit.
Submission
Turn your assignment in via Blackboard. Your zip file, named abc123.zip should contain only your
bash, awk, and sed files.
If you attempt the extra credit, name your file abc123_EC.zip. Without the _EC, your submission
will be graded as normal.
For this assignment, you will use Python 3 to create a simple templating engine. Your program
should take as input a generic template with placeholders for generic data, a set of input files
containing data which should be applied to the template, and a date. Instantiated templates using
the input data will be output to a subdirectory.
This assignment requires only Python. Do not use the command line utilities used in the previous
assignment. You are encouraged to explore the Python standard library (the shutil module may be
particularly useful).
Data Format
Data will be stored in the same format as the data in Assignment 1. For each course with an
enrollment greater than 50, your program will use the provided template to generate an advisory
report specifically for them.
1. Data files (i.e., of the same format as those generated in Assignment 1) will be stored inside
a directory specified by the user.
2. Each file within that directory will be named based on the department code (two or three
uppercase alphabetic characters), a course number (exactly four digits), and ending with an
extension of .crs.
3. A course file consists of exactly five lines:
• dept_code (two or three character string) dept_name (string with possible whitespace)
• course_name (string with possible whitespace)
• course_sched (string: either TH or MWF) course_start (start with no whitespace)
course_end (string with no whitespace)
• credit_hours (integer)
• num_students (integer representing number of enrolled students)
4. Example file named MAT1311.crs
MAT Mathematics
Calculus I
TH 8/26/19 12/11/19
3
62
Assignment 5: More Scripting – Python Edition Page 1 of 4
Templating
Templates will include variable names to be filled in with data using double square brackets. For any
data file of the format described above, each of the variables (including the square brackets) should
be substituted with the data’s actual value. Your program should work for arbitrary templates
using the same variables listed below corresponding to the item values described. More than one
variable may appear per line.
• [[dept_code]]
• [[dept_name]]
• [[course_name]]
• [[course_start]]
• [[course_end]]
• [[credit_hours]]
• [[num_students]]
• [[course_num]] (the course number as specified in the filename of the .crs file)
• [[date]] (see below)
Example Template:*
1 < html >
2 < body >
3 <h1 > NOTICE OF OVERENROLLMENT – COURSE [[ dept_code ]] [[ course_num ]]←-
– [[ date ]] </ h1 >
4 <p >
5 Dear Instructor ,
6 </p >
7 <p >
8 Your course , [[ course_name ]] , scheduled from [[ course_start ]] to←-
[[ course_end ]] , has exceeded normal capacity with an ←-
enrollment of [[ num_students ]] students . This must be ←-
corrected within thirty days or this issue will be referred ←-
to the [[ dept_name ]] department for further review .
9 </p >
10 <p >
11 – Administration
12 </p >
13 </ body >
14 </ html >
* This is only a single example of a single template! You must assume that multiple different
templates, with various combinations of variables, will be ran against your program. Experiment
with exercising your program using your own custom scripts, as none will be provided to you. This
is to emphasize the notion that no single template should be used as a test instrument; your script
will be tested against several unknown-to-you templates.
Assignment 5: More Scripting – Python Edition Page 2 of 4
Date Argument
The third command-line argument should be a date manually entered by the user of the format
MM/DD/YYYY. This value should be substituted anywhere where [[date]] appears.
Output
All output files should be written to the directory defined by the last argument. This directory may
or may not already exist. Each file should be named by the course’s department code and number,
and with the extension .warn.
Script Execution
Your program should be invoked through a single bash file (see below) with four arguments:
data directory, template file, date, and output directory. Assuming the program executes correctly,
no output should be printed to the screen.
$ assign5.py ./data assign5.template 12/16/2021 ./output
Assignment Data
Sample input files can be found in:
/usr/local/courses/ssilvestro/cs3423/Fall19/assign5/data.
Script Files
Your program should consist of exactly one file:
• assign5.py – the main file which is initially invoked
Extra Credit (5 points)
Allow your program to take optional fifth and sixth arguments describing the character(s) surrounding the variables instead of double square brackets. This feature should work for the following
characters as either the opening or closing symbol, “/”, “|”, “}”, and “{”. Note that these can be
in any combination (e.g., starting with “{” and ending with “|”) If no fifth and sixth arguments are
passed, the program should behave as normal. You may assume that if a fifth argument is passed,
a sixth will be present, too.
Example:
$ assign5.py ./data assign5.template 12/16/2021 ./output ’{’ ’|’
The above invocation should replace variables in the template such as {date| instead of [[date]].
Assignment 5: More Scripting – Python Edition Page 3 of 4
Extra credit is not given to late assignments. All requirements must be met to qualify for extra credit.
Submission
Turn your assignment in via Blackboard. Your zip file, named abc123.zip should contain only your
Python file.
If you attempt the extra credit, name your file abc123_EC.zip. Without the _EC, your submission
will be graded as normal.
For this assignment, you will use Python3 to create an alternative to the rm command. This program,
rm.py, will take an arbitrary number of paths as arguments and, for each argument, move them to
∼/rm_trash . If ∼/rm_trash does not already exist, it should be created.
Hint: The shutil module may prove useful.
Duplicate Files
If a file with the same name already exists in ∼/rm_trash , you should append -1 to the end
of the filename before any extension(s) if they exist so that both files are preserved. If a file
with the same name in ∼/rm_trash already has -1, the new file should be appended with -2 and
automatically incremented for subsequent copies.
For example, if a file named file.txt is removed 4 times, ∼/rm_trash should contain the following
four files: file.txt, file-1.txt, file-2.txt, and file-3.txt.
Note: It is possible that a file being removed will already have a dash and a number at the end
of the name. If this is true, you should be sure not modify the original name and only append the
counter. For example, if a file named newfile-1.txt is deleted twice, ∼/rm_trash should contain
newfile-1.txt and newfile-1-1.txt. You may assume that there will be no conflicts in file
names (e.g., rm.py file-1.txt; rm.py file.txt)
Recursion
Your program should recursively delete files if any argument is -r. If -r is not set, directories should
be ignored and your program should print
rm.py: cannot remove ’DIR’: Is a directory
to STDERR once for each directory encountered where DIR is the name of the directory.
When deleting recursively, simply move the directory to ∼/rm_trash using the duplicate naming
rules as described above and leave the contents alone. You do not need to modify the names of the
files within the removed directory.
Paths
If an argument does not point to a file, your program should print
rm.py: cannot remove ’FILE’: No such file or directory
to STDERR once for each invalid argument where FILE is the path given.
When moving a file into ∼/rm_trash you should always place it at the root of the directory.
For example, if /path/to/a/file.txt is passed as an argument, file.txt should be moved to
∼/rm_trash/file.txt and not ∼/rm_trash/path/to/a/file.txt.
Assignment 6: Python Scripting Page 1 of 2
Program Execution
Your program should be invoked as a single Python file (see below) with an arbitrary number of
arguments representing paths to files (including directories). The -r option may be passed as any
argument. Some examples are listed below.
$ rm.py /path/to/some/file ./somefile someotherfile
$ rm.py /path/to/some/file ./somefile someotherfile -r
$ rm.py -r /path/to/some/file ./somefile someotherfile
$ rm.py *.java
Extra Credit (10 points)
For extra credit, create a separate program called restore.py which, given a path to where a file
used to be before it was removed with rm.py, will restore the most recent version.
Hint: Consider keeping track of the original and new locations of removed files to handle situations
where removed files from different paths have the same name. Note that if you use this strategy,
the information will need to persist between executions of rm.py and restore.py.
Attempts at extra credit will not be considered if rm.py does not work correctly.
Assignment Data
No sample data is included with this assignment as it should work for all files. As always, you should
test your program with your own data as well to be sure that it works correctly.
Program Files
Your submission will consist of one or two files depending on if you attempt the extra credit:
• rm.py – implementation of rm
• restore.py – extra credit
Submission
Turn your assignment in via Blackboard. Your zip file, named LastnameFirstname.zip should
contain only your rm.py and optionally restore.py.
If you attempt the extra credit, name your file LastnameFirstname_EC.zip. Without the _EC,
your submission will be graded as normal.
For this assignment, you will use C’s I/O functions to create a simple course catalog database for
administrators to update the details of each course offered by the CS department. The system will
store basic information about each course, allowing the user to create, read, update, and delete them.
All information for all courses will be stored as binary records in a single file.
This assignment requires only the utilities used so far in the I/O lecture notes. Do not use bash, sed,
awk, find, grep, Python, or any programming languages or utilities besides the C binary functions
used in class. Only binary I/O functions should be used to store data to the filesystem (it is OK to
use other functions when prompting the user).
Note: While this assignment is similar to Assignment 1, it is not exactly the same. You should
thoroughly read all of these instructions.
Storing Course Information
All course information will be stored in a single binary structure as records of the following structure,
where courseName is the name of the course (which may contain spaces), courseSched represents
the course schedule (either strings MWF or TR), courseHours is the number of credit hours for the
course, and courseSize is the number of students currently enrolled in the course.
1 typedef struct
2 {
3 char courseName [64];
4 char courseSched [4];
5 unsigned int courseHours ;
6 unsigned int courseSize ;
7 } COURSE ;
The program will store all courses using the above struct in a single file called courses.dat,
located within the same directory as the program (this file is provided to you). All courses will be
referenced using their course number as their index (e.g., course i will be located in the data file
at relative byte off i * sizeof(COURSE). Course records will be stored in courses.dat in coursenumber order. Note that the course numbers will be specified by the user when a course is entered,
and will not necessarily be sequential. If courses.dat does not exist, it should be created by the
program in the current directory. You must use the files located at:
/usr/local/courses/ssilvestro/cs3423/Fall19/assign7; specifically, data/courses.dat shall
be used as the starting point for your database (i.e., you must use this file for all operations, not a
blank/empty/zero-byte data file, nor any other file).
Assignment 7: File I/O Page 1 of 4
Program Execution
When the program is executed, the following actions should occur. All program output should
appear exactly as it appears below.
1. Upon running your program, the user should be presented with the following menu:
Enter one of the following actions or press CTRL-D to exit.
C – create a new course record
R – read an existing course record
U – update an existing course record
D – delete an existing course record
2. The user then enters a one-character action (either upper or lowercase), leading to one of the
following.
• C: a course is created
(a) From the terminal, read the following one line at a time:
i. Course number (zero-indexed integer)
ii. Course name (string possibly containing whitespace)
iii. Course schedule (string ∈ {MWF,TR})
iv. Course credit hours (unsigned integer)
v. Course enrollment (unsigned integer)
(b) Using the values entered by the user, create a new entry in the data file based on
the instructions above.
(c) If the course already exists, print the following error and continue with the program.
The program should detect this and respond immediately after reading the
course number.
ERROR: course already exists
• R: read an existing course’s information
(a) Prompt the user for a course number: (e.g., “3423”)
Enter a CS course number:
(b) Search for the specified course using the provided course number (e.g., “3423”).
(c) Print the course information in the following format:
Course number: course number
Course name: courseName
Scheduled days: courseShed
Credit hours: courseHours
Enrolled Students: courseSize
(d) If the course is not found, print the following error instead and continue with the
program.
Assignment 7: File I/O Page 2 of 4
ERROR: course not found
• U: update an existing course record
(a) Prompt the user for the following one at a time:
i. Course number (zero-indexed integer)
ii. Course name (string possibly containing whitespace)
iii. Course schedule (string ∈ {MWF,TR})
iv. Course credit hours (unsigned integer)
v. Course enrollment (unsigned integer)
(b) Update each of the corresponding fields for the course based on the user’s input. If
the user input is blank for a particular field (except course number), maintain
the original value from the file.
(c) If the course record is not found, print the following error and continue with the
program. You should detect this and respond immediately after reading the
course number.
ERROR: course not found
• D: delete an existing course
(a) Prompt the user for a course number (e.g., “3423”):
Enter a course number:
(b) Delete the specified course’s record.
Hint: You may assume thecreditHours field will never be zero for a valid course.
(c) Print the following message to standard output with the course’s number:
course number was successfully deleted.
(d) If the course is not found, print the following error instead and continue with the
program.
ERROR: course not found
• If an invalid character is entered, print the following error and continue with the program.
ERROR: invalid option
3. After an action is completed, display the menu again. This should proceed indefinitely until
CTRL-D is read, or the end of the file is reached.
Locating Data
For the above functionality, courses.dat should not be read sequentially to search for courses.
The location of the course in courses.dat should be calculated immediately and directly accessed
without performing a search (i.e., no looping!).
Assignment 7: File I/O Page 3 of 4
Assignment Data
Input files for testing can be found in /usr/local/courses/ssilvestro/cs3423/Fall19/assign7
including an existing .dat file and input for stdin. Copy these to your own assignment’s directory.
Important: The input file assumes you are using the provided .dat file. Furthermore, each time
you use the input file, you should refresh the .dat file to its original state.
Compiling Your Program
Your submission will include a makefile so the following command can be used to compile your code.
$ make assign7
Program Files
Your program should consist of up to three files:
• assign7.c – the main file which is compiled (required)
• assign7.h – an optional header file, if necessary
• makefile – the makefile to make the assign7 executable (required)
Verifying Your Program
Your program must work with the input provided in a7Input.txt and courses.dat. To test it:
1. Place courses.dat in the same directory as your compiled program.
2. Execute your compiled program and redirect a7Input.txt into it. You should not be copying
or typing the contents of a7Input.txt into your terminal. Redirection must work.
3. Verify that the output is correct based on the input commands.
4. Execute your program again and use your program’s menu to test that the information was
correctly written to courses.dat.
Submission
Turn in your assignment via Blackboard. Your zip file, named abc123.zip should contain only your
makefile, assign7.c, and possibly assign7.h. Do not include a .dat file.
For this assignment, you will use C’s process control functions to exercise basic process creation.
Your program should have the following functionality:
Concurrency
Given up to six commands separated by commas (a comma will be its own token, with whitespace
around it) and any number of arguments each, execute all commands concurrently (i.e., in parallel
and not one after the other).
Each process (excluding the parent) should print their PID followed by their PPID followed by their
command without arguments to stderr. Any normal behavior by the command issued should remain
the same. You do not need to account for redirection or pipelining.
Your program should not produce orphans. Toward verification of this, if a process’s PPID is 1, it
is an orphan that has been adopted by the init process. In solving this problem, be sure that your
child processes still run concurrently. Do not wait for one process to complete before starting a new
one.
Example
$ assign8 ls -a , pwd , cat hello.txt
PID: 35003, PPID: 35002, CMD: ls
PID: 35004, PPID: 35002, CMD: pwd
Assignment 8: Process Control Page 1 of 3
PID: 35005, PPID: 35002, CMD: cat
/home/ssilvestro
. .. courses Desktop Downloads
this is the contents of hello.txt
Note that since the processes are happening in parallel, the order of the output is not guaranteed.
Compiling Your Program
Your submission will include a makefile so the following command can be used to compile your code.
$ make assign8
This should produce an executable file named assign8. For more information about the make utility,
check the related document on Blackboard.
If you attempt the extra credit, $ make assign8-2 should compile the extra credit portion to
assign8-2.
Extra Credit (10 points)
Create a second program, assign8-2 which takes exactly two commands, with any number of
arguments each, and separated by a comma. The program should pipe the output of the first
command to the second using dup2().
Example
$ assign8-2 ls -l , sort -k5 -n
should behave as
$ ls -l | sort -k5 -n
Extra credit is not given to late assignments. All requirements must be met for both parts of the
assignment to qualify for extra credit.
Assignment Data
This assignment does not include sample input files since it will only take arguments.
Program Files
Your submission should consist of up to five files:
• assign8.c – the main file which is compiled (required)
Assignment 8: Process Control Page 2 of 3
• assign8.h – an optional header file if necessary
• assign8-2.c – the main file which is compiled for extra credit (required for extra credit)
• assign8-2.h – an optional header file if necessary
• Makefile – the makefile to make the assign8 executable (required).
Submission
Turn your assignment in via Blackboard. Your zip file, named abc123.zip should contain only the
files described above.
If you attempt the extra credit, name your file abc123_EC.zip. Without the _EC, your submission
will be graded as normal.
Reviews
There are no reviews yet.