ubuntuusers.de

Curl command mit Variable

Status: Gelöst | Ubuntu-Version: Ubuntu 19.04 (Disco Dingo)
Antworten |

JonesiKC

Anmeldungsdatum:
27. November 2019

Beiträge: 4

Moin,

ich werde gerade nicht schlau draus, vielleicht kann mir ja jemand helfen. Wenn ich den Command rein schreibe funktioniert es.

1
2
3
regcmd=“/home/user/script.sh <host>“

curl -s -k -H 'Content-Type: application/json' -H 'X-Auth-Token: TOKEN‘ -d '{"command": '"$regcmd"'} https://bliblablub.test:8080/execute

Resultat

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>400 Bad Request</title>
<h1>Bad Request</h1>
<p>Failed to decode JSON object: Expecting value: line 1 column 13 (char 12)</p>

Merci

rklm Team-Icon

Projektleitung

Anmeldungsdatum:
16. Oktober 2011

Beiträge: 13213

Herzlich willkommen hier im Forum!

JonesiKC schrieb:

1
2
3
regcmd=“/home/user/script.sh <host>“

curl -s -k -H 'Content-Type: application/json' -H 'X-Auth-Token: TOKEN‘ -d '{"command": '"$regcmd"'} https://bliblablub.test:8080/execute

Du verlierst hier die Double Quotes. Versuch mal dies:

1
2
3
regcmd=“/home/user/script.sh <host>“

curl -s -k -H 'Content-Type: application/json' -H 'X-Auth-Token: TOKEN‘ -d '{"command": "'"$regcmd"'"} https://bliblablub.test:8080/execute

Bist Du sicher, dass die "‘" da hin gehören?

JonesiKC

(Themenstarter)

Anmeldungsdatum:
27. November 2019

Beiträge: 4

MERCI DIR!

"command": "'"$regcmd"'"

DoubelQuote Quote DoubleQuote hat es getan ☺

Antworten |