I got the following command: curl -H 'Content-Type: application/json' -X POST -d '{host: '$(hostname)'}' http://sitename.com/update.phpWhich 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 knowncurl: (6) Could not resolve host: up; Name or service not knowncurl: (7) Failed to connect to 0.0.0.4: Invalid argumentcurl: (6) Could not resolve host: days,; Name or service not knowncurl: (6) Could not resolve host: 5:57,; Name or service not knowncurl: (7) Failed to connect to 0.0.0.3: Invalid argumentcurl: (6) Could not resolve host: users,; Name or service not knowncurl: (6) Could not resolve host: load; Name or service not knowncurl: (6) Could not resolve host: average; Name or service not knowncurl: (6) Could not resolve host: 0.07,; Name or service not knowncurl: (6) Could not resolve host: 0.05,; Name or service not knowncurl: (3) [globbing] unmatched close brace/bracket at pos 6It'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.phpIt gives me 4days, but there must be a better workaround for it :D
How to POST 'shell output' as JSON data with Curl
command line;php;curl;json
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.phpor 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'