I have the following command which, if fired with a hardcoded IP works fine -
ad_request_output="$(/usr/local/nagios/libexec/check_http -w 0.18 -c 0.25 -H <Some private IP> -u 'http://<Some private IP>/fam/postGetAd.php?site_id=76986&partner_id=27de34b6f8b03d81&banner_id=183517&timeout=5000&version=1.5.1&language=jsp&format=wap&phone_headers=REMOTE_ADDR=>166.137.8.134||REMOTE_HOST=>http://localhost||HTTP_USER_AGENT=>Mozilla/5.0')"
echo $ad_request_output gives expected output -
HTTP OK: HTTP/1.1 200 OK - 217 bytes in 0.055 second response time |time=0.054961s;0.180000;0.250000;0.000000 size=217B;;;0
But, using a variable IP gives a different output -
private_ip=<Some private IP>
ad_request_output=$(/usr/local/nagios/libexec/check_http -w 0.18 -c 0.25 -H $private_ip -u 'http://$private_ip/fam/postGetAd.php?site_id=76986&partner_id=27de34b6f8b03d81&banner_id=183517&timeout=5000&version=1.5.1&language=jsp&format=wap&phone_headers=REMOTE_ADDR=>166.137.8.134||REMOTE_HOST=>http://localhost||HTTP_USER_AGENT=>Mozilla/5.0')
echo $ad_request_output gives -
HTTP WARNING: HTTP/1.1 400 Bad Request - 311 bytes in 0.001 second response time |time=0.000703s;0.180000;0.250000;0.000000 size=311B;;;0
Tried with this format of putting variable ${private_ip} as well, but got same output -
ad_request_output=`/usr/local/nagios/libexec/check_http -w 0.18 -c 0.25 -H ${private_ip} -u 'http://${private_ip}/fam/postGetAd.php?site_id=76986&partner_id=27de34b6f8b03d81&banner_id=183517&timeout=5000&version=1.5.1&language=jsp&format=wap&phone_headers=REMOTE_ADDR=>166.137.8.134||REMOTE_HOST=>http://localhost||HTTP_USER_AGENT=>Mozilla/5.0'`
I checked some related questions Bash - Using variable inside command not working but got no clue what am I doing wrong.
I have working code to use variable in a command -
php /var/cake_1.2.0.6311-beta/beforeInstall.php ${OUTPUT}
But, not sure how to do it when the output needs to be collected in a variable.