1

I got the following command:

 curl -H 'Content-Type: application/json' -X POST -d '{"host": "'$(hostname)'"}' http://sitename.com/update.php

Which works as expected, but if I try to send uptime output instead of hostname I get:

curl: (6) Could not resolve host: 19:12; Name or service not known
curl: (6) Could not resolve host: up; Name or service not known
curl: (7) Failed to connect to 0.0.0.4: Invalid argument
curl: (6) Could not resolve host: days,; Name or service not known
curl: (6) Could not resolve host: 5:57,; Name or service not known
curl: (7) Failed to connect to 0.0.0.3: Invalid argument
curl: (6) Could not resolve host: users,; Name or service not known
curl: (6) Could not resolve host: load; Name or service not known
curl: (6) Could not resolve host: average; Name or service not known
curl: (6) Could not resolve host: 0.07,; Name or service not known
curl: (6) Could not resolve host: 0.05,; Name or service not known
curl: (3) [globbing] unmatched close brace/bracket at pos 6

It's obvius being caused by spaces, but how can I scape them?

I can remove spaces with awk:

 curl -H 'Content-Type: application/json' -X POST -d '{"uptime": "'$(uptime | awk '{print $3$4}')'"}' http://sitename.com/update.php

It gives me "4days," but there must be a better workaround for it :D

1 Answer 1

3

Using one type of quote is more simple and solves that issue;

curl -H "Content-Type: application/json" -X POST -d "{\"uptime\": \"$(uptime)\"}" "http://sitename.com/update.php"

or you can use 2 quote types but it's less elegant;

curl -H 'Content-Type: application/json' -X POST -d '{"uptime": "'"$(uptime)"'"}' 'http://sitename.com/update.php'
2
  • nop, it doesn't uptime doesn't gives me any output like this, thats what I got at first and I already fixed it closing the opened single-quote at the start, concatenating with my command, and opening it again to close the brakes
    – Mc Kernel
    Commented Nov 29, 2016 at 18:43
  • oh, my bad, it does indeed work perfectly, thanks!
    – Mc Kernel
    Commented Nov 29, 2016 at 18:44

You must log in to answer this question.

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