Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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://https://postman-echo.com/get?test=123 (Test URL)

Body:
[
{
    "V_1": "test",
    "V_2": "test01",
    "V_3": "test03",
    "V_4": "1"
}
]

This is the shell script which I tried.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#!/bin/sh
res=$(curl --netrc-file ~/.netrc https://postman-echo.com/get?test=123)
echo "Response Received"
echo $res
exit

>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:

#!/bin/sh

# Execute the SQL query
res=$(curl --netrc-file ~/.netrc https://sqlserver.com/query)

# Pass the result of the SQL query to the Rest call
curl -X POST https://postman-echo.com/get -d "{\"V_1\": \"$res\"}"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading