-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.sh
40 lines (36 loc) · 1 KB
/
server.sh
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
#!/bin/bash
# Script for the server to get requests from clients and run them in the background
mkfifo server.pipe # create the server pipe
trap server_shut INT # call exit function when press CTRL+c
# function to trap the I/O interrupt allowing clean exit
function server_shut()
{
echo "...About to exit: Ctrl_c trapped"
rm server.pipe
exit 0
}
id=$1
while true; do
read id req db table row < server.pipe # read input from server pipe
case $req in
create_database)
./create_database.sh $db $table $row > "$id.pipe" & # send output to client pipe
;;
create_table)
./create_table.sh $db $table $row > "$id.pipe" &
;;
insert)
./insert.sh $db $table $row > "$id.pipe" &
;;
query)
./query.sh $db $table $row > "$id.pipe" &
;;
shutdown)
rm server.pipe
exit 0
;;
*)
echo "Error : bad request"
exit 1
esac
done