-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.sh
61 lines (57 loc) · 1.94 KB
/
client.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
# Script for the client sending requests to the server
if [ $# -eq 1 ]; then # check parameter validity
id=$1
mkfifo $id.pipe # create individual client pipe
trap client_shut INT # call exit function when press CTRL+c
# function to trap I/O interrupt allowing clean exit
function client_shut() {
echo "...About to exit: Ctrl_c trapped"
rm $id.pipe
exit 0
}
while true; do
echo "Available commands: create_database, create_table, insert, query, shutdown"
echo "Please enter your request: "
read req db table row # prompt user for a command
case $req in
create_database)
echo $id $req $db $table $row > server.pipe # write user request on the server pipe
read message < $id.pipe # read output on client pipe
echo $message # display output
;;
create_table)
echo $id $req $db $table $row > server.pipe
read message < $id.pipe
echo $message
;;
insert)
echo $id $req $db $table $row > server.pipe
read message < $id.pipe
echo $message
;;
query)
echo $id $req $db $table $row > server.pipe
read message < $id.pipe
if [[ $message == *"Error"* ]]; then
echo $message
else
echo "Start result"
echo $message | sed 's/ /\n/g' # decode message to display table rows on new lines
echo "End result"
fi
;;
shutdown)
rm $id.pipe
exit 0
;;
*)
echo "Error: bad request"
rm $id.pipe
exit 1
esac
done
rm $id.pipe
else
echo "Error: bad client id"
fi