forked from sanger-pathogens/software-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog-query.sh
executable file
·44 lines (35 loc) · 1.01 KB
/
log-query.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
#!/bin/bash
# Example usage:
# ./log-query.sh mm6 img thepath exec p1 'p"2' "p'3"
paso_api_log='http://paso.tol.sanger.ac.uk/log'
json_escape () {
echo "${1//\"/\\\"}"
}
log_usage () {
local user=$(json_escape "${1}") ; shift
local image=$(json_escape "${1}") ; shift
local path=$(json_escape "${1}") ; shift
local executable=$(json_escape "${1}") ; shift
# Escape and quote parameters, if any
local parameters=""
for p in $@
do
parameters=$(printf "${parameters} %s" $p)
done
parameters=$(json_escape "${parameters}")
# Escape into JSON
local post_data=$( printf '{"user":"%s","image":"%s","executable":"%s","path":"%s","parameters":"%s"}' "${user}" "${image}" "${executable}" "${path}" "${parameters}" )
# POST to logging API
curl --silent \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X POST \
--data "${post_data}" \
"${paso_api_log}"
}
if [[ $# < 4 ]]
then
echo "USAGE: log.sh USER_NAME IMAGE_NAME PATH_NAME EXECUTABLE_NAME [PARAMETER PARAMETER ...]"
else
log_usage $@
fi