You are on page 1of 21

Railway Database

Management Using Shell Script

By:
R.J.
CONTENT

SI NO. PARTICULARS PAGE NO.


1 Acknowledgement 1
2 Problem Statement 2
3 Flow Chart or Diagram 3
4 Functions Description 5
5 Code 8
6 Output 17
ACKNOWLEDGEMENT

I would like to express thanks of gratitude to my teacher


Miss Priya Sen & Mr Mazharul Islam who gave me golden
opportunity to do this wonderful project on topic Railway
Database Management Using Shell Script, which also helped
in doing a lot of research and I came to know about so many
new commands.
Secondly, I would like to thank my friends who helped me a
lot in finishing this project within the limited time.
I am making this project not only for marks but to also
increase my knowledge.
THANKS AGAIN TO ALL WHO HELPED ME.
PROBLEM STATEMENT

Create Databases for Railway Database Management System:


(Here databases are nothing but the text files used to store the data and have
DML functions.)

1. Customer Database
2. Train Database

List of Entries (Options) :


1. Add a new person.
2. Select the places where from and where to, date. railway
database schema
3. Select the class. (eg. Sleeper, AC first etc.)
4. View the list of the trains depending on the search.
FLOWCHART OR DIAGRAM
Create a customer database

CName CAge CMob CSex

Create a train database

Tseat

Tfair
SELECTION : Calls add_passenger function where
Option a chossen it reads data from keyboard & enters
a) Add Passenger
customer details (Customer Name ,
details
Customer Age ,Customer Mobile No ,
b) View Specific Customer Sex) into Customer details
train details database.
c) Add train
details
d) View the Calls find_trains function &
customer details searches specific train details on
Option b chossen
e) Exit the basis of entered source ,
destination & date of departure .

Read data from keyboard. Enter


train details (Train Name , Train no
,Arrival time , Departure time ,
etc) into Train_details database.
Option c chossen

Option d chossen Calls view_customerDetails


function & lists all the customer
details from Customer_details
database.

Option e chossen Whole process ends


FUNCTION(S) DESCRIPTION
get_return()
This function is used to return a pointer to a calling function
either view_trainDetails or view_customerDetails or find_trains. Here
variable ‘x’ reads the data from the keyboard.

get_confirm()
This function is used to get confirmation from the user for adding
the information in the database. If user types yes then information is
added to database otherwise it gets cancelled. Here variable ‘x’ is
used to read yes or no from the keyboard.

set_menu_choice()
This function is used to display the options on the terminal.
‘menu_choice’ variable reads user choice from the terminal.

insert_recordCustomer()
This function is used to record permanently customer information
in the customer_details database.

insert_recordTrain()
This function is used to record permanently train information in
the train_details database.
add_passenger()
This function is used to read passenger details and(calling
get_confimation()) after getting confirmation from user adds
data(calling insert_recordCustomer)in database.
CName – reads customer name
Cage – reads customer age
CMob – reads customer mobile number
CS – reads customer sex

add_train()
This function is used to read passenger details and(calling
get_confimation()) after getting confirmation from user adds
data(calling insert_recordTrain)in database.
Tno – reads train number
Tname – reads train name
Tsrc – reads source of the train
Tdes – reads destination of the train
Tdep – reads departure time of the train
Tarv – reads arrival time of the train
Ttype – reads whether coach of train is ac , 2s , sleeper etc
Tquota – reads quota like student , tatkal etc.
Tfair – reads fair per person
Tseat – reads total seat availability
view_trainDetails()
This function is used to view or lists all the train on the terminal
from train_details database.

view_customerDetails()
This function is used to view or lists all the train on the terminal
from customer_details database.

find_trains()
This function is used to find the train details on the basis of user
requirements(train source , train destination & date of journey) from
train_details database.
The grep filter searches a file for a particular pattern of characters,
and displays all lines that contain that pattern
grep -i ignores, case for matching.
grep -i "$src.*$des.*$d" $db1 > $temp_file : stores the found record
in temp_file.
linesfound : stores the count of line present in temp_file

# db1 -> this variable represents train_details database


# db2 -> this variable represents customer_details databsae
CODE
menu_choice=""
db1="train_details"
db2="customer_details"
temp_file=/tmp/ldb.$$
touch $temp_file;
trap 'rm -f $temp_file' EXIT

get_return(){
printf '\tPress return\n'
read x
return 0
}

get_confirm(){
printf '\tAre you sure?\n'
while true
do
read x
case "$x" in
y|yes|Y|Yes|YES)
return 0;;
n|no|N|No|NO)
printf '\ncancelled\n'
return 1;;
*) printf 'Please enter yes or no';;
esac
done
}

set_menu_choice(){
clear
printf 'Options:-'
printf '\n'
printf '\ta) Add Passenger details\n'
printf '\tb) View Specific train details\n'
printf '\tc) Add train details\n'
printf '\td) View the customer details\n'
printf '\te) Exit\n'
printf 'Please enter the choice then press return\n'
read menu_choice
return
}

insert_recordCustomer(){
echo $* >>$db2
return
}

insert_recordTrain(){
echo $* >>$db1
return
}

add_passenger()
{
printf 'Enter CUSTOMER NAME:-'
read tmp
CName=${tmp%%,*}

printf 'Enter CUSTOMER AGE:-'


read tmp
CAge=${tmp%%,*}

printf 'Enter MOBILE NUMBER:-'


read tmp
CMob=${tmp%%,*}

printf 'Enter SEX:-'


read tmp
CS=${tmp%%,*}

#Check that they want to enter the information


printf 'About to add new entry\n'
printf "$CName\t$CAge\t$CMob\t$CS\n"

#If confirmed then append it to the record file


if get_confirm; then
insert_recordCustomer $CName $CAge $CMob $CS
fi
return
}

add_train()
{
printf 'Enter TRAIN NUMBER:-'
read tmp
Tno=${tmp%%,*}

printf 'Enter TRAIN NAME:-'


read tmp
Tname=${tmp%%,*}

printf 'Enter Train Source:-'


read tmp
Tsrc=${tmp%%,*}

printf 'Enter TRAIN DESTINATION:-'


read tmp
Tdes=${tmp%%,*}

printf 'Enter Date:-'


read tmp
Td=${tmp%%,*}

printf 'Enter DEPARTURE TIME:-'


read tmp
Tdep=${tmp%%,*}

printf 'Enter ARRIVAL TIME:-'


read tmp
Tarv=${tmp%%,*}

printf 'Enter COACH type:-'


read tmp
Ttype=${tmp%%,*}

printf 'Enter quota:-'


read tmp
Tquota=${tmp%%,*}

printf 'Enter FAIR PER PERSON:-'


read tmp
Tfair=${tmp%%,*}

printf 'Enter number of seats available:-'


read tmp
Tseat=${tmp%%,*}
#Check that they want to enter the information
printf 'About to add new entry\n'
printf
"$Tno\t$Tname\t$Tsrc\t$Tdes\t$td\t$Tdep\t$Tarv\t$Ttype\t$Tquota\t$Tfair\
t$Tseat\n"

#If confirmed then append it to the record file


if get_confirm; then
insert_recordTrain $Tno $Tname $Tsrc $Tdes $Td $Tdep $Tarv $Ttype
$Tquota $Tfair $Tseat
fi
return
}

view_trainDetails(){
printf "List of train are\n"

cat $db1
get_return
return
}

view_customerDetails(){
printf "List of Customers are\n"

cat $db2
get_return
return
}

find_trains(){
echo "Enter WHERE TO WHERE to find:"
read src
read des
echo "Enter date : "
read d
grep -i "$src.*$des.*$d" $db1 > $temp_file
linesfound=`cat $temp_file|wc -l`

case `echo $linesfound` in


0) echo "Sorry, nothing found"
get_return
return 0
;;
*) echo "Found the following"
cat $temp_file
get_return
return 0
esac
return
}

printf '\n\n\n'
printf 'Mini RAILWAY SYSTEM'
sleep 1

quit="n"
while [ "$quit" != "y" ];
do

#funtion call for choice


set_menu_choice
case "$menu_choice" in
a)rm -f $temp_file
if [ !-f $db2 ];then
touch $db2
fi
add_passenger;;
b) find_trains;;
c) rm -f $temp_file
if [ !-f $db1 ];then
touch $db1
fi
add_train;;
d) view_customerDetails;;
e) quit=y;;
*) printf "Sorry, choice not recognized";;
esac
done
# Tidy up and leave

rm -f $temp_file
echo "Finished"

exit 0
OUTPUT
customer_details
abc 30 1234567890 M
def 22 2145698730 F

train_details
1234 durunto hwh pnbe 30.04.2019 8:00pm 4:30am ac general 990 240
1234 Durunto hwh pnbe 30.04.2019 8:00pm 4:30am sleeper general
350 600
2345 akal kol pnbe 30.04.2019 7:40am 4:30pm ac general 760 115
2345 akal kol pnbe 30.04.2019 7:40am 4:30pm sleeper general 350 600

You might also like