Issue
I am trying to invoke rest api using curl in a loop as shown below. It doesn't work and throws error curl: (6) Couldn't resolve host '$SERVERPROTOCOL:'
However, if replace all environment variables and execute command then it works just fine.
Direct command which works:
curl -X DELETE -k -H 'Content-Type: application/xml' -H 'Accept: application/xml' -u 'testuser:test123' -i 'https://nonprodhost:443/process/cancel/pvm:0a126'
Curl in loop which throws - curl: (6) Couldn't resolve host '$SERVERPROTOCOL:'
for pi in $(cat $halted_pid);do
# write PID to console so user knows script is working
echo
echo "cacnelling process instance - $pi"
# 2>&1 to include any output on stderr
curl -X DELETE -k -H 'Content-Type: application/xml' -H 'Accept: application/xml' -u '$USERNAME:USERPASS' -i '$SERVERPROTOCOL://$SERVERHOST:$SERVERPORT/process/cancel/$pi' 2>&1 | tee -a $halted_pi_cancellation_logfile
done
Solution
Why I think issue is single quote? Try replacing single quotes with double quotes
(reference: https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double )
curl -X DELETE -k -H 'Content-Type: application/xml' -H 'Accept: application/xml' -u '$USERNAME:USERPASS' -i '$SERVERPROTOCOL://$SERVERHOST:$SERVERPORT/process/cancel/$pi' 2>&1 | tee -a $halted_pi_cancellation_logfile
convert to:
curl -X DELETE -k -H "Content-Type: application/xml" -H "Accept: application/xml" -u "$USERNAME:USERPASS" -i "$SERVERPROTOCOL://$SERVERHOST:$SERVERPORT/process/cancel/$pi" 2>&1 | tee -a $halted_pi_cancellation_logfile
Answered By - Smruti ranjan Gochhayat