$20
This assignment, you will use bash create a simple inventory system. The system will store basic information about items and allow the user to create, read, update, delete, and total these items.
This assignment requires only the utilities used so far in the lecture notes. Further, you may not use sed, awk, find, grep, Python, perl, any programming language, scripting language, or other tools not otherwise permitted. The only external tool you may utilize is bc, which can be used to perform floating-point arithmetic.
Storing Item Information
Item information will be stored in text files (ending with the extension .item).
Files will be stored in a directory named data, located within the same directory as your shell script.
Each file will be named based on its unique item number, an integer (henceforth referred to as item_num) with exactly four digits, followed by the extension .item.
An item file consists of exactly three lines, in the following format:item_name (string with no whitespace) simple_name (string)
unit_price (floating point number) cur_qty (unsigned integer) max_qty (unsigned integer)
item_desc (string)
The following are the example contents of an item file named item:
btl_water Bottled Water
(24/pk)
15.99 23 50
Poland Springs natural
spring drinking
water
Script Execution
When the script is run, the following should occur.
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 inventory item
R - read an existing inventory item
U - update an existing inventory item
D - delete an existing inventory item
T - calculate total value of an inventory item
The user then enters a corresponding one-character selection (either upper or lowercase entries should be permissible), leading to one of the following actions:C: create a new inventory record (thus, also creating its associated data file)From the terminal, read the following fields, one at a time, each separated on its own line:Item number: (four digit unsigned integer) Example input: 3293 ii. Item name: (string containing no whitespace) Example input: btl_water iii. Simple name: (string)
Example input: Bottled Water (24/pk) iv. Unit price: (floating point number) Example input: 15.99
Current quantity: (unsigned integer) Example input: 23
Maximum quantity: (unsigned integer) Example input: 50 vii. Description: (string)
Example input: Poland Springs natural spring drinking water
Using the values entered by the user, create a new file in the data subdirectory (which may or may not pre-exist) based on the file naming instructions above.
Update data/queries.log by adding the following line:
[date] CREATED: item_num - item_name - cur_qty / max_qty where:
date is the formatted output from the shell’s ‘date "+[%Y-%M-%d %H:%m:%S]"‘
command,
item_num represents the item’s internal identification number (e.g. 3293),
item_name represents the item’s internal identification string (e.g. btl_water), and
cur_qty represents the item’s initial quantity as of its entry into this inventory system (e.g. 20).
max_qty represents the item’s maximum allowable inventory quantity (e.g. 50).
If the item number already exists, abandon the “Create” operation and print the following example error message, then continue with the script. For example: ERROR: item 3293 already exists
R: read and display an existing item’s inventory information
Prompt the user for an inventory item’s number:
Enter an item number:
Search for the specified inventory item using the item number provided.
Print the item’s inventory information in the following format:
Item Number: item_num
Item Name: item_name
Simple Name: simple_name
Unit Price: unit_price
Quantity: cur_qty / max_qty
Description: item_desc
If the item is not found, print the following example error and continue with the script.
ERROR: item 3293 not found
U: update an existing inventory recordPrompt the user for the following fields one at a time:Item number (four digit unsigned integer)
Item name (string containing no whitespace)
Simple name (string) Unit price (floating point number)
Current quantity (unsigned integer)
Maximum quantity (unsigned integer)
Description (string)
Using the values entered by the user, search for the specified item in the data subdirectory using the given item number.
Update each of the corresponding fields based on the user’s input. If the user input is blank for a particular field (except for the item number), keep the existing value currently utilized within the file.
Update data/queries.log by adding the following line:
[date] UPDATED: item_num - item_name - cur_qty / max_qty where:
date is the formatted output from the shell’s ‘date "+[%Y-%M-%d %H:%m:%S]"‘
command,
item_num represents the item’s internal identification number (e.g. 8299),
item_name represents the item’s internal identification string (e.g. btl_water), and iv. cur_qty represents the item’s currently-stocked quantity (e.g. 12).
max_qty represents the item’s maximum allowable inventory quantity (e.g. 85).
(e) If the item number does not already exist, abandon the “Update” operation and print the following example error message, then continue with the script. For example: ERROR: item 8299 not found
D: delete an existing item’s inventory recordPrompt the user for an item number:
Enter an item number:
Delete the specified item’s file from the data
Update data/queries.log by adding the following line:
[date] DELETED: item_num - item_name - simple_name - cur_qty where:
date is the formatted output from the shell’s ‘date "+[%Y-%M-%d %H:%m:%S]"‘
command,
item_num represents the item’s internal identification number (e.g. 8299),
item_name represents the item’s internal identification string (e.g. btl_water), and
simple_name represents the item’s short-form description (e.g. Bottled Water (24/pk)).
cur_qty represents the item’s currently-stocked quantity (e.g. 12).
(d) If the item number does not already exist, abandon the “Delete” operation and print the following example error message, then continue with the script. For example: ERROR: item 8299 not found
T: calculate total value of current inventory itemsPrompt the user for an item number:
Enter an item number:
Calculate the total value currently in inventory for this specific item (e.g. unit price × current quantity).
Print the following message with the item’s number, simple name, and total value: item_num - simple_name - $(unit_price×cur_qty) total
If the given item number does not exist, abandon the “Total” operation and print the following example error message, then continue with the script. For example: ERROR: item 8299 not found
If an invalid character is entered at the main menu, print the following error message and continue with the script:
ERROR: invalid option
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/Spring20/assign1. Copy this to your own assignment’s directory when you are prepared to begin initial testing. You should not, under any circumstances, rely solely on this data as the only data set with which to test the functionality of your script.
Script Files
Your program should consist of six bash files:
bash - the main file which is to be initially invoked
bash - logic for the create option
bash - logic for the read option
bash - logic for the update option
bash - logic for the delete option
bash - logic for the calculating total value in inventory of a given item
Verifying Your Program
Your program must at least function correctly with the input provided in a1Input.txt. It is extremely important to note that this is NOT the only input your script will be tested with. Thus, think carefully of corner cases and work diligently to test your scripts with large scale input and debug them accordingly, if necessary.
Verify that your assignment folder has a data directory with the initial data set.
Execute your script and redirect txt into it. You should not be copying or typing the contents of a1Input.txt into your terminal. File redirection must work.
For example, the following must work: ./assign1.bash < a1Input.txt
Verify that both the printed output and data files are as expected.