ATM emulation Scripts

Source: Internet
Author: User

#!/bin/bash

# current TIME:2016-11-04 10:40:14


#数据库信息

prot= "3306"

Hostname= "localhost"

Username= "Root"

Password= "123456"

Db_name= "Bank"

Table_name= "bank"

Cmd= "Mysql-u${username}-h${hostname}-p${password}-E"


#验证登录

Verification () {

Read-p "Enter your username:" User

Read-s-P "Enter password:" Pass

Echo

echo "Verifying Please wait ..."

}


Verification

While True

Do

If [' $cmd ' select * from ${db_name}.${table_name} where name= ' ${user} ' and pass= ' ${pass} ' |wc-l '-ne 0];then

Sleep 3

echo "Verified Success"

Break

Else

Sleep 3

echo "User name or password error"

Verification

Fi

Done


#查询

Query () {

money= ' $cmd ' select Money from ${db_name}.${table_name} where name= ' ${user} ' and Pass=${pass} ' | Grep-v "Money"

}


#存款

Deposit () {

Read-p "Enter deposit Amount:" New_money

Let Total=${money}+${new_money}

$cmd "Update ${db_name}.${table_name} set money= ' ${total} ' where Name= ' ${user} ' and Pass=${pass} '

}


#取款

Remove_money () {

Query

Read-p "Enter withdrawal amount:" Remove

If [$remove-gt $money];then

echo "Insufficient balance, Available Balance $money"

Else

Let get= $money-$remove

$cmd "Update ${db_name}.${table_name} set money= ' ${get} ' where Name= ' ${user} ' and Pass=${pass} '

Fi

}


#修改密码

Chage_pass () {

Read-s-P "Enter password:" New_pass

Echo

Read-s-P "Please enter your password again:" Again_pass

Echo

if ["${new_pass}"! = ${again_pass}];then

echo "Two input password is not the same"

Else

$cmd "Update ${db_name}.${table_name} set pass= ' ${new_pass} ' where Name= ' ${user} ' and Pass=${pass} '

Fi

}


While True

Do

Read-p "(Enter the number here) 1: Query 2: Deposit 3: Withdrawal 4: Change Password 5: Exit action


Case ${action} in

1)

Query

Sleep 3

echo "Can Balance of ${money}"

;;

2)

Deposit

Sleep 3

echo "Successful Deposit ${new_money}"

;;

3)

Remove_money

Sleep 3

echo "Successful withdrawal ${remove}, please take good cash"

;;

4)

Chage_pass

Sleep 3

Echo "Operation succeeded"

;;

5)

echo "Thank you, please keep your personal belongings."

Break

;;

Esac

Done


ATM emulation Scripts

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.