-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrySoak.q
More file actions
54 lines (42 loc) · 1.4 KB
/
TrySoak.q
File metadata and controls
54 lines (42 loc) · 1.4 KB
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
#!/bin/sh
if [ $# -lt 3 ]; then
echo "Usage: TrySoak.q <ip address> <zip code> <question> <answer> [<luke writer dd>]"
exit 1
fi
## set -x
set -e
ECHO=/bin/echo
VEGAS=luke.larcnetworks.com
FWD=
IP=$1 ; shift 1
Z=$1 ; shift 1
Q=$1 ; shift 1
A=$1 ; shift 1
if [ $# -eq 1 ]; then
FWD=$1
else
## if we weren't passed a forwarding DD assume we want to create a new pair ...
##
OW=$(echo '{"cmd":"create-dd"}' | nc ${VEGAS} 8089 | perl -ne 'use JSON;
print decode_json($_)->{'owner_token'}, "/", decode_json($_)->{'writer_token'};')
FWD=$(basename ${OW})
echo "Seek will read $(dirname ${OW})"
echo "You will write to ${FWD}"
fi
## send qna to the local cube
##
echo '{"cmd":"index-question","zip":'${Z}',"question":"'${Q}'","answer":"'${A}'","ttl":1440}' | nc ${IP} 8089 > /dev/null
## send qna to luke, prepend question with owner token
##
Q=${FWD}-${Q}
echo '{"cmd":"index-question","zip":'${Z}',"question":"'${Q}'","answer":"'${A}'","ttl":1440}' | nc ${VEGAS} 8089 > /dev/null
${ECHO} -n "Question: ${Q}, "
echo '{"cmd":"index-answer","zip":'${Z}',"question":"'${Q}'"}' | nc ${VEGAS} 8089 | perl -ne 'use JSON;
$idx = 0;
foreach $answer ( @{decode_json($_)} ) {
if ($idx++ == 0) {
printf("owner is %s ...\n", $answer->{'owner'});
}
printf("\t[%02d]: %-32s -- %s\n", $idx, $answer->{'expires'}, $answer->{'answer'});
}'
exit 0