Pass cronjob output as parameter to curl

0

I have cronjob that takes hourly backup. Now I want to pass any stderr to an API.

0 * * * * /usr/local/sbin/script.sh 2>&1 | curl -k -X GET "https://192.168.0.25/path/of/joomla/instance/index.php?option=com_user&task=sendSMSalert&msg=variable"

But I am not sure how to pass the stderr to my API. Please help.

Ash

Posted 2018-08-31T08:38:30.627

Reputation: 97

Answers

0

try something like:

0 * * * * OUTPUT=$((/usr/local/sbin/script.sh) 2>&1)  && curl -k -X GET "https://192.168.0.25/path/of/joomla/instance/index.php?option=com_user&task=sendSMSalert&msg=$OUTPUT"

This way you are assigning the stdout and stderr outputs to the OUTPUT variable, and inserting them into the querystring.

However, I suggest using an HTTP POST and the -d parameter to pass the data to the body instead, in case you're not properly urlencoding the output from script.sh. Using POST you can also try --data-urlencode

andy magoon

Posted 2018-08-31T08:38:30.627

Reputation: 162

Please guide me how to Change this to HTTP POST and the -d parameter to pass the data to the body – Ash – 2018-09-06T11:59:18.807