-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeTransaction
executable file
·48 lines (41 loc) · 1.36 KB
/
makeTransaction
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
source config
read -p "Enter the last four digits of your Account number: " accNo
accNo=ACC`printf %04d $accNo`
ACC_DIR=$(getent passwd $accNo | cut -d: -f6)
balanceFile=$ACC_DIR/Current_Balance.txt
Acc_Balance=`cat $balanceFile`
if [ -z $ACC_DIR ] || ! [ -d $ACC_DIR ] #The user must have permissions to read the directory
# Hence run the script as superUser
then
echo "The user doesn't have an account in our bank"
exit -2 #254
fi
# read -sp "Enter your PIN: " PIN
read -n1 -p "Credit(C) or Debit(D): " transaction ; echo
case $transaction in
c | C)
read -p "Enter amount: " amount
Acc_Balance=$[ Acc_Balance + amount ]
transSymbol="+"
;;
d | D)
read -p "Enter amount: " amount # To check D or C. I hardcoded twice
if [ $Acc_Balance -lt $amount ]
then
echo "Balance not sufficient"
# Here I used Rs. (instead we can use money symbol from locale settings)
echo Available balance is Rs. $Acc_Balance
exit 200
fi
Acc_Balance=$[ Acc_Balance - amount ]
transSymbol="-"
;;*) echo "Invalid Transaction"; exit 100;;
esac
DATE=`date +"%F %H:%M:%S"` # Note the time only if the transaction is successful. Hence, added at last
echo $Acc_Balance > $balanceFile
echo $accNo $transSymbol$amount $DATE >> $ACC_DIR/Transaction_History.txt
echo Transaction Successful
echo Available Balance: Rs. $Acc_Balance
#Model Transaction log
#ACC00022 +7636 2022-03-06 22:26:34