Trigger SQL query using bash script

I have write a shell script which we are calling an API. I now have to trigger a SQL(SELECT) query using shell script. I have to pass that outcome to the POST API. Instead of GET call, I need to trigger POST call. Whatever it the output of the SQL Query(which is a metric value, I need to use it in Rest call.

Can anyone guide how to trigger a SQL query and use that in Rest Call?

https:// (Test URL)

    "V_1": "test",
    "V_2": "test01",
    "V_3": "test03",
    "V_4": "1"

This is the shell script which I tried.

res=$(curl --netrc-file ~/.netrc
echo "Response Received"
echo $res

>Solution :

To solve this, you would need to run the shell script to perform the SQL query and then pass the query result to the Rest call using the request body. For example:


# Execute the SQL query
res=$(curl --netrc-file ~/.netrc

# Pass the result of the SQL query to the Rest call
curl -X POST -d "{\"V_1\": \"$res\"}"

Leave a Reply