shell: evaluate an curl expression

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
-2
down vote

favorite












In this following script i generate a status code and if the statusCode=200, i send the data else if the statusCode !=200 i générate à token and i send the message by recalling eval "$request_cmd".
strong text
But actually when i did this i get this error "command introuvable" at this line eval "$request_cmd". Help please



#!/bin/bash

#variables
randomNumber=$(shuf -i000000-999999 -n1)
eventTime=$(date --rfc-3339=ns | sed 's/ /T/')
idEpc="OneVariable"
fromRecordtime=`date --utc +%FT%T.%3NZ`
goodStatus="200"


printf "n ---------------------------------> SENDING MESSAGE <-------------------------------------- nn"

request_cmd=$(curl -X POST -w "%http_code" --http1.0
"$1/api/acquire/rabbitmq/epcis"
-H 'Authorization: Basic YWtytrytrytrytrW46trttrytrytr'
-H 'Cache-Control: no-cache'
-H 'Content-Type: text/xml'
-H 'Postman-Token: 2c4f9rtertzertertrezatre4'
-H "X-Authorization: Bearer $generatedToken"
-d 'Here i have the data')
echo $request_cmd

if [ "$request_cmd" != "$goodStatus" ]
then
printf "n ---------------------------------> GETTING TOKEN <-------------------------------------- nn"
generatedToken=$(curl -X POST $2/MyURL/token -H 'Cache-Control: no-cache' -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=client_credentials&client_secret=abesdfsd677c-6dsdfsba-4ddfsc8-978fsdfdsfsb-ec256cf65914&client_id=che-gateway' | jq -r .access_token)
eval "$request_cmd"
echo $request_cmd






share|improve this question





















  • $request_cmd will be whatever curl outputs, not the curl command itself.
    – Kusalananda
    Aug 3 at 15:48











  • I think the phrase "i send the message by recalling eval "$request_cmd"." could do with some clarification. (What message? What do you mean with "recalling eval"?)
    – ilkkachu
    Aug 3 at 15:51










  • sorry, i try to evaluate "$request_cmd". when i did this i get error "command introuvable" because this curl command return a statuscode of request
    – BiginByHelloWord
    Aug 3 at 15:52










  • the message is the data in xml format. i mean call the curl request to send the data
    – BiginByHelloWord
    Aug 3 at 15:55










  • simply, how can i get the "http code" of an curl request, then send an message with the same curl request
    – BiginByHelloWord
    Aug 3 at 16:00
















up vote
-2
down vote

favorite












In this following script i generate a status code and if the statusCode=200, i send the data else if the statusCode !=200 i générate à token and i send the message by recalling eval "$request_cmd".
strong text
But actually when i did this i get this error "command introuvable" at this line eval "$request_cmd". Help please



#!/bin/bash

#variables
randomNumber=$(shuf -i000000-999999 -n1)
eventTime=$(date --rfc-3339=ns | sed 's/ /T/')
idEpc="OneVariable"
fromRecordtime=`date --utc +%FT%T.%3NZ`
goodStatus="200"


printf "n ---------------------------------> SENDING MESSAGE <-------------------------------------- nn"

request_cmd=$(curl -X POST -w "%http_code" --http1.0
"$1/api/acquire/rabbitmq/epcis"
-H 'Authorization: Basic YWtytrytrytrytrW46trttrytrytr'
-H 'Cache-Control: no-cache'
-H 'Content-Type: text/xml'
-H 'Postman-Token: 2c4f9rtertzertertrezatre4'
-H "X-Authorization: Bearer $generatedToken"
-d 'Here i have the data')
echo $request_cmd

if [ "$request_cmd" != "$goodStatus" ]
then
printf "n ---------------------------------> GETTING TOKEN <-------------------------------------- nn"
generatedToken=$(curl -X POST $2/MyURL/token -H 'Cache-Control: no-cache' -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=client_credentials&client_secret=abesdfsd677c-6dsdfsba-4ddfsc8-978fsdfdsfsb-ec256cf65914&client_id=che-gateway' | jq -r .access_token)
eval "$request_cmd"
echo $request_cmd






share|improve this question





















  • $request_cmd will be whatever curl outputs, not the curl command itself.
    – Kusalananda
    Aug 3 at 15:48











  • I think the phrase "i send the message by recalling eval "$request_cmd"." could do with some clarification. (What message? What do you mean with "recalling eval"?)
    – ilkkachu
    Aug 3 at 15:51










  • sorry, i try to evaluate "$request_cmd". when i did this i get error "command introuvable" because this curl command return a statuscode of request
    – BiginByHelloWord
    Aug 3 at 15:52










  • the message is the data in xml format. i mean call the curl request to send the data
    – BiginByHelloWord
    Aug 3 at 15:55










  • simply, how can i get the "http code" of an curl request, then send an message with the same curl request
    – BiginByHelloWord
    Aug 3 at 16:00












up vote
-2
down vote

favorite









up vote
-2
down vote

favorite











In this following script i generate a status code and if the statusCode=200, i send the data else if the statusCode !=200 i générate à token and i send the message by recalling eval "$request_cmd".
strong text
But actually when i did this i get this error "command introuvable" at this line eval "$request_cmd". Help please



#!/bin/bash

#variables
randomNumber=$(shuf -i000000-999999 -n1)
eventTime=$(date --rfc-3339=ns | sed 's/ /T/')
idEpc="OneVariable"
fromRecordtime=`date --utc +%FT%T.%3NZ`
goodStatus="200"


printf "n ---------------------------------> SENDING MESSAGE <-------------------------------------- nn"

request_cmd=$(curl -X POST -w "%http_code" --http1.0
"$1/api/acquire/rabbitmq/epcis"
-H 'Authorization: Basic YWtytrytrytrytrW46trttrytrytr'
-H 'Cache-Control: no-cache'
-H 'Content-Type: text/xml'
-H 'Postman-Token: 2c4f9rtertzertertrezatre4'
-H "X-Authorization: Bearer $generatedToken"
-d 'Here i have the data')
echo $request_cmd

if [ "$request_cmd" != "$goodStatus" ]
then
printf "n ---------------------------------> GETTING TOKEN <-------------------------------------- nn"
generatedToken=$(curl -X POST $2/MyURL/token -H 'Cache-Control: no-cache' -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=client_credentials&client_secret=abesdfsd677c-6dsdfsba-4ddfsc8-978fsdfdsfsb-ec256cf65914&client_id=che-gateway' | jq -r .access_token)
eval "$request_cmd"
echo $request_cmd






share|improve this question













In this following script i generate a status code and if the statusCode=200, i send the data else if the statusCode !=200 i générate à token and i send the message by recalling eval "$request_cmd".
strong text
But actually when i did this i get this error "command introuvable" at this line eval "$request_cmd". Help please



#!/bin/bash

#variables
randomNumber=$(shuf -i000000-999999 -n1)
eventTime=$(date --rfc-3339=ns | sed 's/ /T/')
idEpc="OneVariable"
fromRecordtime=`date --utc +%FT%T.%3NZ`
goodStatus="200"


printf "n ---------------------------------> SENDING MESSAGE <-------------------------------------- nn"

request_cmd=$(curl -X POST -w "%http_code" --http1.0
"$1/api/acquire/rabbitmq/epcis"
-H 'Authorization: Basic YWtytrytrytrytrW46trttrytrytr'
-H 'Cache-Control: no-cache'
-H 'Content-Type: text/xml'
-H 'Postman-Token: 2c4f9rtertzertertrezatre4'
-H "X-Authorization: Bearer $generatedToken"
-d 'Here i have the data')
echo $request_cmd

if [ "$request_cmd" != "$goodStatus" ]
then
printf "n ---------------------------------> GETTING TOKEN <-------------------------------------- nn"
generatedToken=$(curl -X POST $2/MyURL/token -H 'Cache-Control: no-cache' -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=client_credentials&client_secret=abesdfsd677c-6dsdfsba-4ddfsc8-978fsdfdsfsb-ec256cf65914&client_id=che-gateway' | jq -r .access_token)
eval "$request_cmd"
echo $request_cmd








share|improve this question












share|improve this question




share|improve this question








edited Aug 3 at 16:44









Jeff Schaller

30.7k846104




30.7k846104









asked Aug 3 at 15:39









BiginByHelloWord

11




11











  • $request_cmd will be whatever curl outputs, not the curl command itself.
    – Kusalananda
    Aug 3 at 15:48











  • I think the phrase "i send the message by recalling eval "$request_cmd"." could do with some clarification. (What message? What do you mean with "recalling eval"?)
    – ilkkachu
    Aug 3 at 15:51










  • sorry, i try to evaluate "$request_cmd". when i did this i get error "command introuvable" because this curl command return a statuscode of request
    – BiginByHelloWord
    Aug 3 at 15:52










  • the message is the data in xml format. i mean call the curl request to send the data
    – BiginByHelloWord
    Aug 3 at 15:55










  • simply, how can i get the "http code" of an curl request, then send an message with the same curl request
    – BiginByHelloWord
    Aug 3 at 16:00
















  • $request_cmd will be whatever curl outputs, not the curl command itself.
    – Kusalananda
    Aug 3 at 15:48











  • I think the phrase "i send the message by recalling eval "$request_cmd"." could do with some clarification. (What message? What do you mean with "recalling eval"?)
    – ilkkachu
    Aug 3 at 15:51










  • sorry, i try to evaluate "$request_cmd". when i did this i get error "command introuvable" because this curl command return a statuscode of request
    – BiginByHelloWord
    Aug 3 at 15:52










  • the message is the data in xml format. i mean call the curl request to send the data
    – BiginByHelloWord
    Aug 3 at 15:55










  • simply, how can i get the "http code" of an curl request, then send an message with the same curl request
    – BiginByHelloWord
    Aug 3 at 16:00















$request_cmd will be whatever curl outputs, not the curl command itself.
– Kusalananda
Aug 3 at 15:48





$request_cmd will be whatever curl outputs, not the curl command itself.
– Kusalananda
Aug 3 at 15:48













I think the phrase "i send the message by recalling eval "$request_cmd"." could do with some clarification. (What message? What do you mean with "recalling eval"?)
– ilkkachu
Aug 3 at 15:51




I think the phrase "i send the message by recalling eval "$request_cmd"." could do with some clarification. (What message? What do you mean with "recalling eval"?)
– ilkkachu
Aug 3 at 15:51












sorry, i try to evaluate "$request_cmd". when i did this i get error "command introuvable" because this curl command return a statuscode of request
– BiginByHelloWord
Aug 3 at 15:52




sorry, i try to evaluate "$request_cmd". when i did this i get error "command introuvable" because this curl command return a statuscode of request
– BiginByHelloWord
Aug 3 at 15:52












the message is the data in xml format. i mean call the curl request to send the data
– BiginByHelloWord
Aug 3 at 15:55




the message is the data in xml format. i mean call the curl request to send the data
– BiginByHelloWord
Aug 3 at 15:55












simply, how can i get the "http code" of an curl request, then send an message with the same curl request
– BiginByHelloWord
Aug 3 at 16:00




simply, how can i get the "http code" of an curl request, then send an message with the same curl request
– BiginByHelloWord
Aug 3 at 16:00










1 Answer
1






active

oldest

votes

















up vote
1
down vote













There are several issues here.




In this following script i generate a status code and if the statusCode=200




That isn't what your code does. It puts both the status code and any document that comes back into the variable $request_cmd. This might not cause you a problem right now, if the document is empty, but it's a little sloppy.



See https://superuser.com/questions/272265/getting-curl-to-output-http-status-code




I send the data else if the statusCode !=200 I generate a token and I send the message by recalling eval "$request_cmd"




This isn't what your code does. Suppose you run the first curl, and you get back something like "401 Unauthorized." eval will try to run the command "401," but there is no command called that.



I think you mean to use bash functions here. You can use a bash function to run the same piece of code multiple times.



Here is an example of what I mean:



function request_cmd 
status_code=$(curl -s -o /dev/null -X POST -w "%http_code" --http1.0
"$1/api/acquire/rabbitmq/epcis"
-H 'Authorization: Basic YWtytrytrytrytrW46trttrytrytr'
-H 'Cache-Control: no-cache'
-H 'Content-Type: text/xml'
-H 'Postman-Token: 2c4f9rtertzertertrezatre4'
-H "X-Authorization: Bearer $generatedToken"
-d 'Here i have the data')
echo $status_code

request_cmd # calls curl and puts result into $status_code
generatedToken=foo # changes the value of generatedToken
request_cmd # calls curl again with new generatedToken value





share|improve this answer





















  • Hi Nick ODell, you have exactly understood my problem. i need to call the curl without generating token cause in some environment we don't need to generate a token this i why i use the condition "if status code!=200" we generate à token and retry to send the data with the same curl command.
    – BiginByHelloWord
    20 hours ago










  • Does this answer solve your problem, then?
    – Nick ODell
    16 hours ago










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460360%2fshell-evaluate-an-curl-expression%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













There are several issues here.




In this following script i generate a status code and if the statusCode=200




That isn't what your code does. It puts both the status code and any document that comes back into the variable $request_cmd. This might not cause you a problem right now, if the document is empty, but it's a little sloppy.



See https://superuser.com/questions/272265/getting-curl-to-output-http-status-code




I send the data else if the statusCode !=200 I generate a token and I send the message by recalling eval "$request_cmd"




This isn't what your code does. Suppose you run the first curl, and you get back something like "401 Unauthorized." eval will try to run the command "401," but there is no command called that.



I think you mean to use bash functions here. You can use a bash function to run the same piece of code multiple times.



Here is an example of what I mean:



function request_cmd 
status_code=$(curl -s -o /dev/null -X POST -w "%http_code" --http1.0
"$1/api/acquire/rabbitmq/epcis"
-H 'Authorization: Basic YWtytrytrytrytrW46trttrytrytr'
-H 'Cache-Control: no-cache'
-H 'Content-Type: text/xml'
-H 'Postman-Token: 2c4f9rtertzertertrezatre4'
-H "X-Authorization: Bearer $generatedToken"
-d 'Here i have the data')
echo $status_code

request_cmd # calls curl and puts result into $status_code
generatedToken=foo # changes the value of generatedToken
request_cmd # calls curl again with new generatedToken value





share|improve this answer





















  • Hi Nick ODell, you have exactly understood my problem. i need to call the curl without generating token cause in some environment we don't need to generate a token this i why i use the condition "if status code!=200" we generate à token and retry to send the data with the same curl command.
    – BiginByHelloWord
    20 hours ago










  • Does this answer solve your problem, then?
    – Nick ODell
    16 hours ago














up vote
1
down vote













There are several issues here.




In this following script i generate a status code and if the statusCode=200




That isn't what your code does. It puts both the status code and any document that comes back into the variable $request_cmd. This might not cause you a problem right now, if the document is empty, but it's a little sloppy.



See https://superuser.com/questions/272265/getting-curl-to-output-http-status-code




I send the data else if the statusCode !=200 I generate a token and I send the message by recalling eval "$request_cmd"




This isn't what your code does. Suppose you run the first curl, and you get back something like "401 Unauthorized." eval will try to run the command "401," but there is no command called that.



I think you mean to use bash functions here. You can use a bash function to run the same piece of code multiple times.



Here is an example of what I mean:



function request_cmd 
status_code=$(curl -s -o /dev/null -X POST -w "%http_code" --http1.0
"$1/api/acquire/rabbitmq/epcis"
-H 'Authorization: Basic YWtytrytrytrytrW46trttrytrytr'
-H 'Cache-Control: no-cache'
-H 'Content-Type: text/xml'
-H 'Postman-Token: 2c4f9rtertzertertrezatre4'
-H "X-Authorization: Bearer $generatedToken"
-d 'Here i have the data')
echo $status_code

request_cmd # calls curl and puts result into $status_code
generatedToken=foo # changes the value of generatedToken
request_cmd # calls curl again with new generatedToken value





share|improve this answer





















  • Hi Nick ODell, you have exactly understood my problem. i need to call the curl without generating token cause in some environment we don't need to generate a token this i why i use the condition "if status code!=200" we generate à token and retry to send the data with the same curl command.
    – BiginByHelloWord
    20 hours ago










  • Does this answer solve your problem, then?
    – Nick ODell
    16 hours ago












up vote
1
down vote










up vote
1
down vote









There are several issues here.




In this following script i generate a status code and if the statusCode=200




That isn't what your code does. It puts both the status code and any document that comes back into the variable $request_cmd. This might not cause you a problem right now, if the document is empty, but it's a little sloppy.



See https://superuser.com/questions/272265/getting-curl-to-output-http-status-code




I send the data else if the statusCode !=200 I generate a token and I send the message by recalling eval "$request_cmd"




This isn't what your code does. Suppose you run the first curl, and you get back something like "401 Unauthorized." eval will try to run the command "401," but there is no command called that.



I think you mean to use bash functions here. You can use a bash function to run the same piece of code multiple times.



Here is an example of what I mean:



function request_cmd 
status_code=$(curl -s -o /dev/null -X POST -w "%http_code" --http1.0
"$1/api/acquire/rabbitmq/epcis"
-H 'Authorization: Basic YWtytrytrytrytrW46trttrytrytr'
-H 'Cache-Control: no-cache'
-H 'Content-Type: text/xml'
-H 'Postman-Token: 2c4f9rtertzertertrezatre4'
-H "X-Authorization: Bearer $generatedToken"
-d 'Here i have the data')
echo $status_code

request_cmd # calls curl and puts result into $status_code
generatedToken=foo # changes the value of generatedToken
request_cmd # calls curl again with new generatedToken value





share|improve this answer













There are several issues here.




In this following script i generate a status code and if the statusCode=200




That isn't what your code does. It puts both the status code and any document that comes back into the variable $request_cmd. This might not cause you a problem right now, if the document is empty, but it's a little sloppy.



See https://superuser.com/questions/272265/getting-curl-to-output-http-status-code




I send the data else if the statusCode !=200 I generate a token and I send the message by recalling eval "$request_cmd"




This isn't what your code does. Suppose you run the first curl, and you get back something like "401 Unauthorized." eval will try to run the command "401," but there is no command called that.



I think you mean to use bash functions here. You can use a bash function to run the same piece of code multiple times.



Here is an example of what I mean:



function request_cmd 
status_code=$(curl -s -o /dev/null -X POST -w "%http_code" --http1.0
"$1/api/acquire/rabbitmq/epcis"
-H 'Authorization: Basic YWtytrytrytrytrW46trttrytrytr'
-H 'Cache-Control: no-cache'
-H 'Content-Type: text/xml'
-H 'Postman-Token: 2c4f9rtertzertertrezatre4'
-H "X-Authorization: Bearer $generatedToken"
-d 'Here i have the data')
echo $status_code

request_cmd # calls curl and puts result into $status_code
generatedToken=foo # changes the value of generatedToken
request_cmd # calls curl again with new generatedToken value






share|improve this answer













share|improve this answer



share|improve this answer











answered Aug 3 at 17:34









Nick ODell

8922819




8922819











  • Hi Nick ODell, you have exactly understood my problem. i need to call the curl without generating token cause in some environment we don't need to generate a token this i why i use the condition "if status code!=200" we generate à token and retry to send the data with the same curl command.
    – BiginByHelloWord
    20 hours ago










  • Does this answer solve your problem, then?
    – Nick ODell
    16 hours ago
















  • Hi Nick ODell, you have exactly understood my problem. i need to call the curl without generating token cause in some environment we don't need to generate a token this i why i use the condition "if status code!=200" we generate à token and retry to send the data with the same curl command.
    – BiginByHelloWord
    20 hours ago










  • Does this answer solve your problem, then?
    – Nick ODell
    16 hours ago















Hi Nick ODell, you have exactly understood my problem. i need to call the curl without generating token cause in some environment we don't need to generate a token this i why i use the condition "if status code!=200" we generate à token and retry to send the data with the same curl command.
– BiginByHelloWord
20 hours ago




Hi Nick ODell, you have exactly understood my problem. i need to call the curl without generating token cause in some environment we don't need to generate a token this i why i use the condition "if status code!=200" we generate à token and retry to send the data with the same curl command.
– BiginByHelloWord
20 hours ago












Does this answer solve your problem, then?
– Nick ODell
16 hours ago




Does this answer solve your problem, then?
– Nick ODell
16 hours ago












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460360%2fshell-evaluate-an-curl-expression%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?