'Passing quoted argument in json payload to shell script
I am working on a python script that passes arguments to a shell script that lives in a Docker container. I'm achieving this using this Go webhook tool (https://github.com/adnanh/webhook). So far I've had success passing simple arguments to my shell script via the requests module. However, I've hit a roadblock.
The purpose of my tool is to trigger a dna assembly program that has a number of optional parameters that can be tuned by users. Currently, I have been triggering the webhook like so:
def trigger_assembler(out, assem_opts):
id = "assemble"
payload = {"FWD": f"-f data/{out}/R1.fq", "REV": f"-r data/{out}/R2.fq", "OUT": f"-o {out}",
"OPT": f'-p \" {assem_opts} \"'}
try:
r = requests.post(f"http://0.0.0.0:9000/hooks/{id}", json=payload)
r.raise_for_status()
except requests.exceptions.RequestException as e: # This is the correct syntax
raise SystemExit(e)
In the shell script I am parsing the arguments and then trying to execute the following command:
nohup Trinity --left "${FWD}" --right "${REV}" "${ASSEM_ARGS}" \
--output data/"${OUT}"/trinity &
I have tried escaping the double quotes as you see in the example code. I have tried various numbers of backslashes after reading other stack overflow answers. I have tried simply using single quotes for the f-string and using double quotes within the string. None of these approaches has worked. No matter what I do there is a backslash present in the arguments delivered to my shell script, which obviously is problematic.
Also, I have tested the shell script in isolation with arguments of the form that I am hoping to pass and it works fine, so the problem seems to not be on that end.
Thanks for your help.
Solution 1:[1]
If anyone comes here looking for an answer, I never found one! I decided to store information in a yaml file that was accessible to all containers in my system. I would still very much like to know how to work around this problem in the future.
Solution 2:[2]
try this, pass-arguments-to-command pass argument as array start from 1
source: https://github.com/adnanh/webhook/issues/357
another reference https://gitlab.com/-/snippets/1972594
//payload json
{
"data": {
"id": "1651565",
"username": "change me"
}
}
---
//hook.json
[
{
"id": "payload",
"execute-command": "/path/to/command.sh",
"response-message": "Executing simple webhook...",
"pass-arguments-to-command":
[
{
"source": "payload",
"name": "data.id"
},
{
"source": "payload",
"name": "data.username"
}
]
}
]
---
//command.sh
#!/bin/sh
ID=$1
USERNAME=$2
echo $ID //1651565
echo $USERNAME //change me
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bennett Lambert |
Solution 2 | Octavian A. D. Cahyadi |