I need to run a curl command on a container running in kubernetes cluster via PowerShell. Now, with curl, i need to pass various headers containing long token Strings. However, when i execute the command, the command string gets split in midway and terminal enters into newline mode from which I am not able to exit.
Below is the command.
curl -X GET http://sit-product-abcd-xyzx-adapter:8080/prdcopy/projects/PROJECT-NOVEMBER2020-eCom-SPORT_STYLE-3 -H "authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlhSQVFGbGs3V0tNWnFzRm1ZUDcxaE55U3c4TSIsImtpZCI6IlhSQVFGbGs3V0tNWnFzRm1ZUDcxaE55U3c4TSJ9.eyJhdWQiOiJodHRwczovL2Rldi5hcGkuYWRpZGFzLmNvbS9jb3JwbWFya2V0L3ByZGNvcHkiLCJpc3MiOiJodHRwOi8vc3RzLXRlc3QuYWRpZGFzLWdyb3VwLmNvbS9hZGZzL3NlcnZpY2VzL3RydXN0IiwiaWF0IjoxNTYzOTUyOTI5LCJuYmYiOjE1NjM5NTI5MjksImV4cCI6MTU2Mzk1NjUyOSwic3ViIjoic3ZjX3BjYXBpIiwiZGlzdGluZ3Vpc2hlZG5hbWUiOiJDTj1zdmNfcGNhcGksT1U9U2VydmljZUFjY291bnRzLE9VPVVzZXJzLE9VPUVNQWRtaW5pc3RyYXRpb24sREM9ZW1lYSxEQz1h456bnQsREM9Yml6IiwiYXBwdHlwZSI6IkNvbmZpZGVudGlhbCIsImFwcGlkIjoiNTA4NzM2YTAtNzM5Mi00ODBkLTlmYWQtYWQ5NzUwMDI3ZjVhIiwiYXV0aG1ldGhvZCI6InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDphYzpjbGFzc2VzOlBhc3N3b3JkUHJvdGVjdGVkVHJhbnNwb3J0IiwiYXV0aF90aW1lIjoiMjAxOS0wNy0yNFQwNzoyMjowOS43NTFaIiwidmVyIjoiMS4wIiwic2NwIjoidXNlcl9pbXBlcnNvbmF0aW9uIG9wZW5pZCJ9.kBrQO48rK_lkhDeZIQkW_If9lcYn5kERiif1VtlcXAPQ_j94KDGTfrmvF9f89EeyzExZSHFnCx0HyI8tvpeklEypWGchI4qG8V8z-AjTBrmKnX6mMSVLYaoh0TsLdeaFX-ByQ4TmyXzt5jje-CcS62w8P1J3aalVNhlTUp9e5rtP9qpttu2QmA482anQSsS6GN6ltJY9NyjfrW-ElZRrPXunIAf16jOjG0ehEUS8GpUJnc-wStJnF_zYuvnb-4m2GqzXqDHtpEvojg5N0Luq07z2mMpeEXbrGx-0fScjkSAsCJ8E-sFpbBYSXOCHfCslUPjM07kyzaZaa9tgWJGrGA" -H "cache-control: no-cache" -H "content-type: application/json" -H "project-id-type: API"
However, when i enter this command in power-shell after entering into the container, it looks like below.
PS R:\> kubectl exec -it sit-pcapi-order-event-consumer-b6f4c8797-m578d -- sh
/opt/app # curl -X GET http://sit-product-abcd-xyzx-adapter:8080/prdcopy/projects/PROJECT-NOVEMBER2020-eCom-SPORT_STYLE-
3 -H "authorization: bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6IlhSQVFGbGs3V0tNWnFzRm1ZUDcxaE55U3c4TSIsImtpZCI6
IlhSQVFGbGs3V0tNWnFzRm1ZUDcxaE55U3c4TSJ9.eyJhdWQiOiJodHRwczovL2Rldi5hcGkuYWRpZGFzLmNvbS9jb3JwbWFya2V0L3ByZGNvcHkiLCJpc3M
iOiJodHRwOi8vc3RzLXRlc3QuYWRpZGFzLWdyb3VwLmNvbS9hZGZzL3NlcnZpY2VzL3RydXN0IiwiaWF0IjoxNTYzOTUyOTI5LCJuYmYiOjE1NjM5NTI5Mjk
sImV4cCI6MTU2Mzk1NjUyOSwic3ViIjoic3ZjX3BjYXBpIiwiZGlzdGluZ3Vpc2hlZG5hbWUiOiJDTj1zdmNfcGNhcGksT1U9U2VydmljZUFjY291bnRzLE9
VPVVzZXJzLE9VPUVNQWRtaW5pc3RyYXRpb24sREM9ZW1lYSxEQz1h456bnQsREM9Yml6IiwiYXBwdHlwZSI6IkNvbmZpZGVudGlhbCIsImFwcGlkIjoiNTA4
NzM2YTAtNzM5Mi00ODBkLTlmYWQtYWQ5NzUwMDI3ZjVhIiwiYXV0aG1ldGhvZCI6InVybjpvYXNpczpuYW1lczp0YzpTQU1MOjIuMDphYzpjbGFzc2VzOlBh
c3N3b3JkUHJvdGVjdGVkVHJhbnNwb3J0IiwiYXV0aF90aW1lIjoiMjAxOS0wNy0yNFQwNzoyMjowOS43NTFaIiwidmVyIjoiMS4wIiwic2NwIjoidXNlcl9p
bXBlcnNvbmF0aW9uIG9wZW5pZCJ9.kBrQO48rK_lkhDeZIQkW_If9lcYn5kERiif1VtlcXAPQ
>
>
>
After this, i need to close the terminal and re-login into the container and kill the sh process manually.
How can i exit this curl command in power-shell? How can i execute long curl commands? I tried powershell_ise, but in that, i am not able to execute kubectl exec command. After executing that command, the terminal remains stuck forever.
Maybe you can copy the token as file into the container/pod and then pass it to curl as file.
More or less like this:
# Copy file
kubectl cp /tmp/token namespace/sit-pcapi-order-event-consumer-b6f4c8797-m578d:/tmp/token
# Pass the token as file instead of literal
kubectl exec -it sit-pcapi-order-event-consumer-b6f4c8797-m578d -- sh /opt/app # curl -X GET http://.../ -H #header_file $URL
Regards
Related
I wrote a curl script to pull data from my api url into my unix terminal. But when I run the script below, I get a blank space as my output, rather than data from the api url. I don't get any standard error message, just a blank space followed by $ to enter a new command.
#!/bin/bash
INSTANCE_NAME="https://servicenow.com/ServiceNowData/tickets?ticks=4320000"
DATA_OUTPUT=$(curl -s -k -X GET -H "accept: application/json" $INSTANCE_NAME)
echo $DATA_OUTPUT
Page 404. And -H "Accept-Encoding: application/json"
I would like to create a curl output live in a single shell command, to log a output from an Ansible job in realtime filling a log file.
I've tried this command:
curl -f -k -N -H 'Content-Type: application/json' -XPOST \
--user admin:awxsecret \
http://192.168.42.100/api/v2/jobs/1620/
...but it only returns the output generated thus far, not waiting for newly-generated content.
As #charles-duffy said: "AWX does support websockets" I will work with this solution.
I want to load a file from a clients webserver. This webserver is running local only. To get there I have to use ssh. I need the content as well as the return value (e.g. SSH connection broke, webserver down).
What do I have to change? My first try:
#!/bin/bash
RETURN=0
CONTENT=""
sshpass -p xxxxxx ssh root#172.17.1.33 "curl -X POST http://127.0.0.1:10000/status -H 'Content-Type: application/json' > $CONTENT | bash; RETURN=$?"
If you want to get the exit code of curl and the return value of curl:
#!/bin/bash
CONTENT=$(sshpass -p xxxxxx ssh root#172.17.1.33 "curl -X POST http://127.0.0.1:10000/status -H 'Content-Type: application/json'")
RETURN=$?
echo "$RETURN, $CONTENT"
In your script you set the variables on the server you ssh'ed into.
I know a similar question was posted, but I can't get it to work on my machine.
I tried the 1st answer from the mentioned question, i.e. response=$(curl --write-out %{http_code} --silent --output /dev/null servername) and when I echo $response I got 000 [Not sure if that is the desired output].
However, when trying to do so with my cURL command, I get no output.
This is my command:
curl -k --silent --ftp-pasv --ftp-ssl --user C:is_for_cookies --cert localcert_cert.pem --key certs/localcert_pkey.pem ftps://10.10.10.10:21/my_file.txt
and I use it with
x=$(curl -k --silent --ftp-pasv --ftp-ssl --user C:is_for_cookies --cert localcert_cert.pem --key certs/localcert_pkey.pem ftps://10.10.10.10:21/my_file.txt)
but when I try to echo $x all I get is a newline...
I know the cURL is failing, because when I run the same command, without --silent, I get curl: (7) Couldn't connect to server
This Q is tagged with both sh, bash because I've tried it on both with same results
I found this option which kind of helps (but I still don't know how to assign it to a variable, which should be easier than this...):
--stderr <file>
Redirect all writes to stderr to the specified file instead. If the file name is a plain '-', it is instead written to stdout.
If this option is used several times, the last one will be used.
When I use it like this:
curl -k --silent -S --stderr my_err_file --ftp-pasv --ftp-ssl --user C:is_for_cookies --cert localcert_cert.pem --key certs/localcert_pkey.pem ftps://10.10.10.10:21/my_file.txt
I can see the errors (i.e. curl: (7) Couldn't connect to server) inside that file.
I used --silent to suppress all output, and -S to un-suppress the errors, and the --stderr <file> to redirect them
I have been trying to execute curl command from a script file.
The command is as follows (the IP address is stored in variable ip):
curl -s -X POST ${ip1} -H \"content-type: application/json\" -d \''{"args":["org1","scatest'$j$i'","27-06-2018"]}'\'
It's throwing an error saying "cannot read property", if I execute from the script file.
Whereas if I execute from the command line then there is no problem.
Can anybody help me out why curl command is not getting executed from the script file?
Since the discussions under the comment has lead to a solution that works well. I'm gonna put it into answer for the record and in case anyone else runs into the same pitfall.
The problem was caused by excessive quoting which would result in extra quotes being made part of the request, correct form of the command was:
curl -s -X POST ${ip1} -H "content-type: application/json" \
-d '{"args":["org1","scatest'$j$i'","27-06-2018"]}'