Using bash (not a higher-level language), construct a program which manages cust
ID: 3881447 • Letter: U
Question
Using bash (not a higher-level language), construct a program which manages customer files. Each customer has a separate file . Your program will interactively manage customer ac counts Customer File Content .One file per customer, named the customer's email address Each customer file contains two records: 1. Identification record which has two attributes: Customer Email Customer Full Name Account record which has four attributes: Apartment Number-format (APT-xx) Monthly Rent Amt Account Balance Next Due Date 2. Example customer file contents board@xyz.com Bill Board APT-5A 1100 300 2017-10-01 Action Menu Display a menu which shows Enter one of the following actions or press CTRL-D to exit. C-create a customer file P- accept a customer payment F-find customer by apartment number . Read a one-character action. Based on the action, do the following: C-CREATE create a customer file From the terminal, read (each from separate read requests) o Customer Email o Customer Full Name o Apartment Number o Monthly Rent Amt o Next Due Date Default the Account Balance to the monthly rent amount Create a new customer file using the customer's email as the file name. If the file already exists, show an error message (and do nothing) Assume that each of the five attributes should be read before checking for prion existence P PAYMENT-accept customer payment From the terminal, read o Customer Email o Payment AmountExplanation / Answer
proj1.bash
--------------------------------------------------------------------------
echo 'Enter one of the following actions or press CTRL-D to exit.'
echo 'C - create a customer file'
echo 'P - accept a customer payment'
echo 'F - find customer by apartment number'
while read -p 'Enter your choice: ' choice; do
echo ""
case "$choice" in
[Cc]*) ./create.bash;;
[Pp]*) ./payment.bash;;
[Ff]*) ./find.bash;;
*) echo 'Error: invalid action value';;
esac
echo -e " Enter one of the following actions or press CTRL-D to exit."
echo 'C - create a customer file'
echo 'P - accept a customer payment'
echo 'F - find customer by apartment number'
done
-----------------------------------------------------------------------------------
create.bash
-------------------------------------------------
read -p "Enter customer e-mail: " email
read -p "Enter customer's full name: " name
read -p "Enter customer's apartment number (APT-XX): " aptnum
read -p "Enter the monthly rent amount: " rent
read -p "Enter the next due date for rent (YYYY-MM-DD): " duedate
# Check if file already exists
if [ -e "Data/$email" ]; then
echo -e " Error: customer already exists"
exit 1
fi
echo "$email $name" > "Data/$email"
echo "$aptnum $rent 0.00 $duedate" >> "Data/$email"
---------------------------------------------------------------------------------------
find.bash
----------------------------------------
read -p "Enter customer's apartment number (APT-XX): " aptnum
# Find file containing $aptnum with grep, filename (i.e. email) is assigned to variable
filename=$(grep -rl $aptnum Data)
if [ -z $filename ]; then
echo -e " Error: apartment number not found"
exit 1
fi
. ./read.bash < $filename
echo -e " Email: $email"
echo "Name: $firstname $lastname"
echo "Apt: $apt"
echo "Balance: $balance"
echo "Rent Amt: $rent"
echo "Due Date: $duedate"
---------------------------------------------------------------------------------------
payment.bash
-----------------------------------------------
read -p "Enter customer email: " email
read -p "Enter payment amount: " payment
if [ ! -e "Data/$email" ]; then
echo -e " Error: customer not found"
exit 1
fi
. ./read.bash < "Data/$email"
# Calculate balance after subtracting payment
newbalance=$(echo "scale=2; $balance + $payment" | bc)
echo -e "$email $firstname $lastname $apt $rent $newbalance $duedate" > "Data/$email"
----------------------------------------------------------------------------------------
read.bash
-----------------------------------
read email firstname lastname
read apt rent balance duedate
---------------------------------------------------------------------------------------
p1Input.txt
------------------------------------------------
C
polyester@material.com
Poly Ester
APT-2C
900
2017-11-01
P
aking@xyz.com
900
C
board@xyz.com
Peg Board
APT-2F
900
2017-11-02
F
APT-3D
F
APT-3F
P
bhead@xyz.com
950
P
perrymecium@bio.com
1000
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.