shell: evaluate an curl expression
Clash 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
bash shell-script curl
add a comment |Â
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
bash shell-script curl
$request_cmd
will be whatevercurl
outputs, not thecurl
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
add a comment |Â
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
bash shell-script curl
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
bash shell-script curl
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 whatevercurl
outputs, not thecurl
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
add a comment |Â
$request_cmd
will be whatevercurl
outputs, not thecurl
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
$request_cmd
will be whatevercurl
outputs, not thecurl
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