0

if I run this command in linux shell.

curl=`curl --connect-timeout 4 -k -X POST -H "Content-type: text/xml" --data "<MyRequest><HeartBeat timestamp=\"1311157780201\"></HeartBeat></MyRequest>" http://192.168.1.100:8484/rest/service?action=heartbeat 2>&1 | tee`

echo "$curl"

I get following response

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<MyResponse><HeartBeat status="SUCCESS"></HeartBeat></MyResponse>

But when the same command is executed in a bash CGI script and output is displayed in html pre tags, I see some weird table and no XML data is displayed at all.

in CGI bash script i have this code

    curl=`curl --connect-timeout 4 -k -X POST -H "Content-type: text/xml" --data "<MyRequest><HeartBeat timestamp=\"1311157780201\"></HeartBeat></MyRequest>" http://192.168.1.100:8484/rest/service?action=heartbeat 2>&1 | tee`

echo "<h2> RAW Troubleshooting Data </h2><pre>"
echo "$curl"
echo "</pre>"
exit 0

instead of XML data, following table is displayed in the web browser.

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  

Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0    76      0    424 --:--:-- --:--:-- --:--:--   424
202   126    0   126    0    76    302    182 --:--:-- --:--:-- --:--:--   210

However, if I use the curl verbosity with -v command in cgi bash script I get following out in my web browser but still the XML response is missing.

* About to connect() to xx.xx.xx.xx port xxxxx (#0)
*   Trying xx.xx.xx.xx... connected
* Connected to xx.xx.xx.xx (xx.xx.xx.xx) port xxxxx (#0)
> POST /rest/service?action=heartbeat HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.15.3 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: xx.xx.xx.xx:xxxx
> Accept: */*
> Content-type: text/xml
> Content-Length: 76
> 
} [data not shown]
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0    76      0    422 --:--:-- --:--:-- --:--:--   422< HTTP/1.1 200 OK
< Server: nginx
< Date: Thu, 14 Nov 2019 18:53:44 GMT
< Content-Type: application/xml
< Transfer-Encoding: chunked
< Connection: keep-alive
< Vary: Accept-Encoding
< X-Powered-By: PHP/7.0.32
< 
{ [data not shown]

202   126    0   126    0    76    284    171 --:--:-- --:--:-- --:--:--   190
202   126    0   126    0    76    284    171 --:--:-- --:--:-- --:--:--   190* Connection #0 to host xx.xxx.xxx.xx left intact

* Closing connection #0

Your help is appreciated.

1 Answer 1

0

The table you see is curl’s informational output about what it’s doing. It goes to STDERR. You are redirecting STDERR to STDOUT (2>&1), so that’s why you are seeing it.

You need to either remove that redirect or silence curl output by adding --silent. As for why you don’t get the output you want, that’s not entirely clear but the | tee at the end looks superfluous and is missing a target file name so won’t be helping matters.

3
  • ok, If I remove (2>&1) and remove pipe tee command, also tried using -s or --silent argument, but then page becomes completely blank, no output is displayed at all. Nov 14, 2019 at 19:39
  • That is odd. What happens if you add --output /tmp/something and you do cat /tmp/something instead of the echo? Is that still blank?
    – bxm
    Nov 14, 2019 at 20:22
  • It is the stupid browser that is not displaying the result. Everything always worked, I can see the XML data in the file, but when echo in pre tags within html it is not displayed by the browser. Thanks for your help Nov 15, 2019 at 9:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .