I've one cron task to update my DDNS with my current ip address and do it through a cURL call.
The problem is one of the parameters to pass in the call is the CURRENT IP and in order to discover ir i need to do another cURL call.
I would like to know if is possible to nest two cURL calls in one single script in order to make my cron task avoiding extra scripts
example:
to get my current ip I use
curl ipinfo.io/ip
to update my ddns i need to do:
curl -X PUT "https://api.cloudflare.com/client/v4/zones/2wertyh/dns_records/23ertghj" \
-H "X-Auth-Email: tomatechines#gmail.com" \
-H "X-Auth-Key: 123ertgyh" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":"qwsdfg.com.br","content":"MY-CURRENT-IP","ttl":1800,"proxied":false}'
how can i fit this two calls together in order to make my cron task
Use command substitution, like this:
curl -X PUT "https://api.cloudflare.com/client/v4/zones/2wertyh/dns_records/23ertghj" \
-H "X-Auth-Email: tomatechines#gmail.com" \
-H "X-Auth-Key: 123ertgyh" \
-H "Content-Type: application/json" \
--data '{"type":"A","name":"qwsdfg.com.br","content":"'"$(curl ipinfo.io/ip)"'","ttl":1800,"proxied":false}'
String argument for --data is composed from three concatenated parts, 'beginning' "$(curl ...)" 'ending' (more details see in this answer).
Related
Can some one tell how to pass multiple extra_vars variables from the command line which will run the Job Template in Tower?
I've followed Ansible documentaion https://docs.ansible.com/ansible-tower/latest/html/userguide/job_templates.html#passing-extra-variables-to-provisioning-callbacks
curl -f -H 'Content-Type: application/json' -XPOST \
-d '{"host_config_key": "efref3d9-740f-429c-43r2-15t326b76", "extra_vars": "{\"Job_ID\": \"24\"},{\"job_templates\": \"test99\"}"}' \
https://tower-ansible.com:443/api/v2/job_templates/822/callback/ -k
For single variable it's working. Below curl command works with single extra variable
curl -f -H 'Content-Type: application/json' -XPOST -d '{"host_config_key": "efref3d9-740f-429c-43r2-15t323b76", "extra_vars": "{\"job_id\": \"24\"}"}' https://tower-ansible.com:443/api/v2/job_templates/822/callback/ -k
According the documentation about Passing Extra Variables to Provisioning Callbacks you have referenced you may
Use the following JSON format as an example when adding your own extra_vars to be passed
"extra_vars": {"variable1":"value1","variable2":"value2",...}
instead of as in your provided example
"extra_vars": {"variable1":"value1"},{"variable2":"value2"}
My code consists of the following:
curl -k -X DELETE \
-H "X-Parse-Application-Id: staticid" \
-H "X-Parse-Master-Key: statickey" \
https://mystatic.url/dynamicvalue
I have a list of URLS:
https://mystatic.url/johndylan
https://mystatic.url/marypoppins
etc, included in a tobedeleted.txt file and I would like to modify my cURL code to be something like this (which I've tried but didnt work:
curl -k -X DELETE \
-H "X-Parse-Application-Id: staticid" \
-H "X-Parse-Master-Key: statickey" \
> tobedeleted.txt
or to something like this (which also I've tried but it didnt worked)
curl -k -X DELETE \
-H "X-Parse-Application-Id: staticid" \
-H "X-Parse-Master-Key: statickey" \
https://mystatic.url/$tobedeleted.txt
Note that i want to run the same cURL command, each time for each line of the file, so I guess that I would need something like foreach function, since this is a bash script.
You are going to want something like this:
while read value
do
curl -k -X DELETE \
-H "X-Parse-Application-Id: staticid" \
-H "X-Parse-Master-Key: statickey" \
https://mystatic.url/$value
done < tobedeleted.txt
I've tried just about every combination of single quotes, double quotes and backslashes that I can think of. If anyone could please point out what I'm doing wrong that'd be greatly appreciated.
run_locally do
execute "\\curl -X POST \"https://api.cloudflare.com/client/v4/zones/#{fetch(:cloudflare_zone)}/purge_cache\" \
-H \"X-Auth-Email: test#example.com\" \
-H \"X-Auth-Key: #{fetch(:cloudflare_api)}\" \
-H \"Content-Type: application/json\" \
--data {\"purge_everything\":true}\""
end
My capistrano script dies when it hits this every time. I feel like it's that last line but I'm not sure why.
Edit: I've gotten past that error, but now get "Malformed JSON in request body" back from Cloudflare.
run_locally do
execute "\\curl -X POST \"https://api.cloudflare.com/client/v4/zones/#{fetch(:cloudflare_zone)}/purge_cache\" \
-H \"X-Auth-Email: test#example.com\" \
-H \"X-Auth-Key: #{fetch(:cloudflare_api)}\" \
-H \"Content-Type: application/json\" \
--data \"{\"purge_everything\":true}\" "
end
So for some reason it doesn't like my --data section.
I'm not able to check this directly for you, but you can use other string constructs to do this in a clearer way which will hopefully highlight the issue for you.
run_locally do
execute %{curl -X POST "https://api.cloudflare.com/client/v4/zones/#{fetch(:cloudflare_zone)}/purge_cache" \
-H "X-Auth-Email: test#example.com" \
-H "X-Auth-Key: #{fetch(:cloudflare_api)}" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}'}
end
It's probably the nested double quotes in your JSON causing the issue.
I have a simple bash script that call cURL with several params.
I need to write the output in a file (also overwriting). But I cannot do.
The call itself works, but I have only an empty file (and the answer is a json, I can read on the shell with that echo)
Thank you in advance for your help
1st try
curl -X POST "https://www.example.com"\
-H "X-Auth-Email: $email"\
-H "X-Auth-Key: $auth_key"\
-H "Content-Type: application/json"\
--data '{"name":"'$name'","surname":"'$surname'"}'
>> id.txt
echo
2nd try
curl -X POST "https://www.example.com"\
-H "X-Auth-Email: $email"\
-H "X-Auth-Key: $auth_key"\
-H "Content-Type: application/json"\
--data '{"name":"'$name'","surname":"'$surname'"}'
o id.txt
echo
curl -X POST "https://www.example.com"\
-H "X-Auth-Email: $email"\
-H "X-Auth-Key: $auth_key"\
-H "Content-Type: application/json"\
--data '{"name":"'$name'","surname":"'$surname'"}'\
-o id.txt
I am able to execute the below cURL request (generated in PostMan) through a Git Bash in windows, and receive a response as expected.
curl -X GET \ https://test.amazon.com/production/john.stones \
-H 'authorization: Bearer dfgjdrjkdrt' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: 53a3fs9a-5ce3-10fe-7f0a-33e9695ec514' \
-H 'referer: king'
I wish to run multiple cURL requests, around a thousand like the above, with the name being the value that changes in each request. I tried placing them into a batch file but each line is taken as a command, so a bit unsure as to how to structure them. Anyone know how I can run multiple cURL requests, either in sequence or parallel, in Windows 10?
I have addressed this by listing each cURL request in a batch file, replacing all single quotes with double and removed all '\' generated in Postman to divide headers. Only after this does windows run the requests successfully.