Looping by replacing the values in a file and then doing curl request for 25 times increasing count by 1000
Clash Royale CLAN TAG#URR8PPP
I have a scenario of doing a curl request with payload from a file to my server. Here I need to replace values in my file incrementing values by 1000 and repeating the same for 25 times. I am able to replace the values by 'sed' but I am not able to loop it for 25 times.
Here is what I implemented for one time.
curl -H "text/xml" --data-binary "@/home/miracle/email/somainput1.xml" https://x.x.x.x:5550 --insecure -u admin:xxxxx >> somaoutput1.xml
my input file has the following code..
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<dp:request domain="HUB" xmlns:dp="http://www.datapower.com/schemas/management">
<dp:b2b-query-metadata>
<dp:query>
<dp:query-condition evaluation="property-equals">
<dp:property-name>ResultCode</dp:property-name>
<dp:value>0</dp:value>
</dp:query-condition>
<dp:query-condition evaluation="logical-and">
<dp:query-condition evaluation="property-greater-than">
<dp:property-name>InputTime</dp:property-name>
<dp:value>2019-02-19 23:00:00</dp:value>
</dp:query-condition>
<dp:query-condition evaluation="property-less-than">
<dp:property-name>InputTime</dp:property-name>
<dp:value>2019-02-20 11:00:00</dp:value>
</dp:query-condition>
</dp:query-condition>
</dp:query>
<dp:result-constraints>
<dp:max-rows>1000</dp:max-rows>
**<dp:start-index>18001</dp:start-index>**
<dp:include-properties>
<dp:property-name>SenderName</dp:property-name>
<dp:property-name>ReceiverName</dp:property-name>
<dp:property-name>ResultCode</dp:property-name>
</dp:include-properties>
</dp:result-constraints>
</dp:b2b-query-metadata>
</dp:request>
</soapenv:Body>
</soapenv:Envelope>
and I can able to replace it by sed using
sed -i '23s/18001/19001/g' b2bsoapinput.xml
I need to do the loop and send the same curl request 25 times.
linux text-processing sed curl
add a comment |
I have a scenario of doing a curl request with payload from a file to my server. Here I need to replace values in my file incrementing values by 1000 and repeating the same for 25 times. I am able to replace the values by 'sed' but I am not able to loop it for 25 times.
Here is what I implemented for one time.
curl -H "text/xml" --data-binary "@/home/miracle/email/somainput1.xml" https://x.x.x.x:5550 --insecure -u admin:xxxxx >> somaoutput1.xml
my input file has the following code..
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<dp:request domain="HUB" xmlns:dp="http://www.datapower.com/schemas/management">
<dp:b2b-query-metadata>
<dp:query>
<dp:query-condition evaluation="property-equals">
<dp:property-name>ResultCode</dp:property-name>
<dp:value>0</dp:value>
</dp:query-condition>
<dp:query-condition evaluation="logical-and">
<dp:query-condition evaluation="property-greater-than">
<dp:property-name>InputTime</dp:property-name>
<dp:value>2019-02-19 23:00:00</dp:value>
</dp:query-condition>
<dp:query-condition evaluation="property-less-than">
<dp:property-name>InputTime</dp:property-name>
<dp:value>2019-02-20 11:00:00</dp:value>
</dp:query-condition>
</dp:query-condition>
</dp:query>
<dp:result-constraints>
<dp:max-rows>1000</dp:max-rows>
**<dp:start-index>18001</dp:start-index>**
<dp:include-properties>
<dp:property-name>SenderName</dp:property-name>
<dp:property-name>ReceiverName</dp:property-name>
<dp:property-name>ResultCode</dp:property-name>
</dp:include-properties>
</dp:result-constraints>
</dp:b2b-query-metadata>
</dp:request>
</soapenv:Body>
</soapenv:Envelope>
and I can able to replace it by sed using
sed -i '23s/18001/19001/g' b2bsoapinput.xml
I need to do the loop and send the same curl request 25 times.
linux text-processing sed curl
add a comment |
I have a scenario of doing a curl request with payload from a file to my server. Here I need to replace values in my file incrementing values by 1000 and repeating the same for 25 times. I am able to replace the values by 'sed' but I am not able to loop it for 25 times.
Here is what I implemented for one time.
curl -H "text/xml" --data-binary "@/home/miracle/email/somainput1.xml" https://x.x.x.x:5550 --insecure -u admin:xxxxx >> somaoutput1.xml
my input file has the following code..
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<dp:request domain="HUB" xmlns:dp="http://www.datapower.com/schemas/management">
<dp:b2b-query-metadata>
<dp:query>
<dp:query-condition evaluation="property-equals">
<dp:property-name>ResultCode</dp:property-name>
<dp:value>0</dp:value>
</dp:query-condition>
<dp:query-condition evaluation="logical-and">
<dp:query-condition evaluation="property-greater-than">
<dp:property-name>InputTime</dp:property-name>
<dp:value>2019-02-19 23:00:00</dp:value>
</dp:query-condition>
<dp:query-condition evaluation="property-less-than">
<dp:property-name>InputTime</dp:property-name>
<dp:value>2019-02-20 11:00:00</dp:value>
</dp:query-condition>
</dp:query-condition>
</dp:query>
<dp:result-constraints>
<dp:max-rows>1000</dp:max-rows>
**<dp:start-index>18001</dp:start-index>**
<dp:include-properties>
<dp:property-name>SenderName</dp:property-name>
<dp:property-name>ReceiverName</dp:property-name>
<dp:property-name>ResultCode</dp:property-name>
</dp:include-properties>
</dp:result-constraints>
</dp:b2b-query-metadata>
</dp:request>
</soapenv:Body>
</soapenv:Envelope>
and I can able to replace it by sed using
sed -i '23s/18001/19001/g' b2bsoapinput.xml
I need to do the loop and send the same curl request 25 times.
linux text-processing sed curl
I have a scenario of doing a curl request with payload from a file to my server. Here I need to replace values in my file incrementing values by 1000 and repeating the same for 25 times. I am able to replace the values by 'sed' but I am not able to loop it for 25 times.
Here is what I implemented for one time.
curl -H "text/xml" --data-binary "@/home/miracle/email/somainput1.xml" https://x.x.x.x:5550 --insecure -u admin:xxxxx >> somaoutput1.xml
my input file has the following code..
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<dp:request domain="HUB" xmlns:dp="http://www.datapower.com/schemas/management">
<dp:b2b-query-metadata>
<dp:query>
<dp:query-condition evaluation="property-equals">
<dp:property-name>ResultCode</dp:property-name>
<dp:value>0</dp:value>
</dp:query-condition>
<dp:query-condition evaluation="logical-and">
<dp:query-condition evaluation="property-greater-than">
<dp:property-name>InputTime</dp:property-name>
<dp:value>2019-02-19 23:00:00</dp:value>
</dp:query-condition>
<dp:query-condition evaluation="property-less-than">
<dp:property-name>InputTime</dp:property-name>
<dp:value>2019-02-20 11:00:00</dp:value>
</dp:query-condition>
</dp:query-condition>
</dp:query>
<dp:result-constraints>
<dp:max-rows>1000</dp:max-rows>
**<dp:start-index>18001</dp:start-index>**
<dp:include-properties>
<dp:property-name>SenderName</dp:property-name>
<dp:property-name>ReceiverName</dp:property-name>
<dp:property-name>ResultCode</dp:property-name>
</dp:include-properties>
</dp:result-constraints>
</dp:b2b-query-metadata>
</dp:request>
</soapenv:Body>
</soapenv:Envelope>
and I can able to replace it by sed using
sed -i '23s/18001/19001/g' b2bsoapinput.xml
I need to do the loop and send the same curl request 25 times.
linux text-processing sed curl
linux text-processing sed curl
edited Mar 1 at 17:28
Rui F Ribeiro
41.8k1483142
41.8k1483142
asked Mar 1 at 10:38
harishchowdaryharishchowdary
31
31
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
A command you could loop over is
sed -n '23s/[^0-9]*([0-9]*)[^0-9]*/1+1000/p'
b2bsoapinput.xml | bc | xargs -I sed -i
'23s/([^0-9]*)[0-9]*([^0-9]*)/12/g' b2bsoapinput.xml
So you could run
for i in 1..25; do
curl -H "text/xml" --data-binary
"@/home/miracle/email/b2bsoapinput.xml"
https://x.x.x.x:5550 --insecure -u admin:xxxxx
>> somaoutput$i.xml || break
sed -n '23s/[^0-9]*([0-9]*)[^0-9]*/1+1000/p'
b2bsoapinput.xml | bc | xargs -I
sed -i '23s/([^0-9]*)[0-9]*([^0-9]*)/12/g'
b2bsoapinput.xml
done
The first sed
matches the only number in line 23 and replaces it with number+1000
. The .../p
tells sed to print the replaced value and -n
tells it to not print the changed file. Hence only the replacement string is piped on to bc
wich does the aritmetics. The second sed replaces the only number in line 23 with the new value and changes the file in place. I used xargs to put the piped value into the sed argument. The -I
sets the string that is replaced by the piped value to .
Edit: I added a || break
in the loop. This causes the loop to "stop" if the preseeding command fails (returns an exit code other than 0) and the program to continue after the loop. However, if curl does exit with 0 even when it receives an error response you need to call break
on another condition. Maybe something like grep "an error text" somaoutput$i.xml && break
.
If you want your program to continue with the next iteration of the loop instead of after it you can use continue
instead of break
.
It is my pleasure :)
– katosh
Mar 1 at 12:01
Hello Katosh, for above code I have to check a condition before looping the increments depends on the response code. Lets say we have a response at 22nd request as "request exceeds the limit" then it should stop increments and executes next command.
– harishchowdary
Mar 4 at 19:10
So you want to skip the number if curl fails?
– katosh
Mar 4 at 19:16
yes, and also need to do the same calls for 4 different servers
– harishchowdary
Mar 4 at 19:19
In your questions, you stated the number in the downloaded file should always be incremented by 1000. No matter what that number is. If you want to have curl retry until it succeeds I could edit that in my answer. What exactly should happen when it fails?
– katosh
Mar 4 at 19:39
|
show 2 more comments
Do like this, its basic loop
#!/bin/bash
for i in 1..25; do
# put the code you want to loop 25 times here
done
Or oneline:
$ for i in 1..25; do #your code here ; done
To increment values and substitute them, try this:
!/bin/bash
counter=1
for i in 1..25; do
# Send CURL request
curl -H "text/xml" --data-binary
"@/home/miracle/email/b2bsoapinput.xml"
https://x.x.x.x:5550 --insecure -u admin:xxxxx
>> somaoutput$i.xml
# inc_counter will hold values 1000 bigger than counter
# we will replace value of counter with inc_counter in text file
inc_counter=$(expr $counter + 1000)
# replace values
sed -i "23s/$counter/$inc_counter/g" b2soapinput.xml
# Increment counter by 1000
let "counter+=1000"
done
Thank You for this. But how about replacing the incremented values with 1000 starting from 1 to 25001
– harishchowdary
Mar 1 at 11:34
@harishchowdary i edited the answer
– Tryna Learn Somethin
Mar 1 at 11:56
Thank you....What if I want to loop and increment the count by 1000 based on the curl response?
– harishchowdary
Mar 5 at 9:29
This is gonna start from 1 and with each request in text file will substitute the value with the one that is 1000 greater
– Tryna Learn Somethin
Mar 5 at 10:07
yes I understand, but I want the loop to be incremented based on the curl response. Means I want to validate the response, upon that needs to increment the loop
– harishchowdary
Mar 5 at 10:27
add a comment |
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',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f503738%2flooping-by-replacing-the-values-in-a-file-and-then-doing-curl-request-for-25-tim%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
A command you could loop over is
sed -n '23s/[^0-9]*([0-9]*)[^0-9]*/1+1000/p'
b2bsoapinput.xml | bc | xargs -I sed -i
'23s/([^0-9]*)[0-9]*([^0-9]*)/12/g' b2bsoapinput.xml
So you could run
for i in 1..25; do
curl -H "text/xml" --data-binary
"@/home/miracle/email/b2bsoapinput.xml"
https://x.x.x.x:5550 --insecure -u admin:xxxxx
>> somaoutput$i.xml || break
sed -n '23s/[^0-9]*([0-9]*)[^0-9]*/1+1000/p'
b2bsoapinput.xml | bc | xargs -I
sed -i '23s/([^0-9]*)[0-9]*([^0-9]*)/12/g'
b2bsoapinput.xml
done
The first sed
matches the only number in line 23 and replaces it with number+1000
. The .../p
tells sed to print the replaced value and -n
tells it to not print the changed file. Hence only the replacement string is piped on to bc
wich does the aritmetics. The second sed replaces the only number in line 23 with the new value and changes the file in place. I used xargs to put the piped value into the sed argument. The -I
sets the string that is replaced by the piped value to .
Edit: I added a || break
in the loop. This causes the loop to "stop" if the preseeding command fails (returns an exit code other than 0) and the program to continue after the loop. However, if curl does exit with 0 even when it receives an error response you need to call break
on another condition. Maybe something like grep "an error text" somaoutput$i.xml && break
.
If you want your program to continue with the next iteration of the loop instead of after it you can use continue
instead of break
.
It is my pleasure :)
– katosh
Mar 1 at 12:01
Hello Katosh, for above code I have to check a condition before looping the increments depends on the response code. Lets say we have a response at 22nd request as "request exceeds the limit" then it should stop increments and executes next command.
– harishchowdary
Mar 4 at 19:10
So you want to skip the number if curl fails?
– katosh
Mar 4 at 19:16
yes, and also need to do the same calls for 4 different servers
– harishchowdary
Mar 4 at 19:19
In your questions, you stated the number in the downloaded file should always be incremented by 1000. No matter what that number is. If you want to have curl retry until it succeeds I could edit that in my answer. What exactly should happen when it fails?
– katosh
Mar 4 at 19:39
|
show 2 more comments
A command you could loop over is
sed -n '23s/[^0-9]*([0-9]*)[^0-9]*/1+1000/p'
b2bsoapinput.xml | bc | xargs -I sed -i
'23s/([^0-9]*)[0-9]*([^0-9]*)/12/g' b2bsoapinput.xml
So you could run
for i in 1..25; do
curl -H "text/xml" --data-binary
"@/home/miracle/email/b2bsoapinput.xml"
https://x.x.x.x:5550 --insecure -u admin:xxxxx
>> somaoutput$i.xml || break
sed -n '23s/[^0-9]*([0-9]*)[^0-9]*/1+1000/p'
b2bsoapinput.xml | bc | xargs -I
sed -i '23s/([^0-9]*)[0-9]*([^0-9]*)/12/g'
b2bsoapinput.xml
done
The first sed
matches the only number in line 23 and replaces it with number+1000
. The .../p
tells sed to print the replaced value and -n
tells it to not print the changed file. Hence only the replacement string is piped on to bc
wich does the aritmetics. The second sed replaces the only number in line 23 with the new value and changes the file in place. I used xargs to put the piped value into the sed argument. The -I
sets the string that is replaced by the piped value to .
Edit: I added a || break
in the loop. This causes the loop to "stop" if the preseeding command fails (returns an exit code other than 0) and the program to continue after the loop. However, if curl does exit with 0 even when it receives an error response you need to call break
on another condition. Maybe something like grep "an error text" somaoutput$i.xml && break
.
If you want your program to continue with the next iteration of the loop instead of after it you can use continue
instead of break
.
It is my pleasure :)
– katosh
Mar 1 at 12:01
Hello Katosh, for above code I have to check a condition before looping the increments depends on the response code. Lets say we have a response at 22nd request as "request exceeds the limit" then it should stop increments and executes next command.
– harishchowdary
Mar 4 at 19:10
So you want to skip the number if curl fails?
– katosh
Mar 4 at 19:16
yes, and also need to do the same calls for 4 different servers
– harishchowdary
Mar 4 at 19:19
In your questions, you stated the number in the downloaded file should always be incremented by 1000. No matter what that number is. If you want to have curl retry until it succeeds I could edit that in my answer. What exactly should happen when it fails?
– katosh
Mar 4 at 19:39
|
show 2 more comments
A command you could loop over is
sed -n '23s/[^0-9]*([0-9]*)[^0-9]*/1+1000/p'
b2bsoapinput.xml | bc | xargs -I sed -i
'23s/([^0-9]*)[0-9]*([^0-9]*)/12/g' b2bsoapinput.xml
So you could run
for i in 1..25; do
curl -H "text/xml" --data-binary
"@/home/miracle/email/b2bsoapinput.xml"
https://x.x.x.x:5550 --insecure -u admin:xxxxx
>> somaoutput$i.xml || break
sed -n '23s/[^0-9]*([0-9]*)[^0-9]*/1+1000/p'
b2bsoapinput.xml | bc | xargs -I
sed -i '23s/([^0-9]*)[0-9]*([^0-9]*)/12/g'
b2bsoapinput.xml
done
The first sed
matches the only number in line 23 and replaces it with number+1000
. The .../p
tells sed to print the replaced value and -n
tells it to not print the changed file. Hence only the replacement string is piped on to bc
wich does the aritmetics. The second sed replaces the only number in line 23 with the new value and changes the file in place. I used xargs to put the piped value into the sed argument. The -I
sets the string that is replaced by the piped value to .
Edit: I added a || break
in the loop. This causes the loop to "stop" if the preseeding command fails (returns an exit code other than 0) and the program to continue after the loop. However, if curl does exit with 0 even when it receives an error response you need to call break
on another condition. Maybe something like grep "an error text" somaoutput$i.xml && break
.
If you want your program to continue with the next iteration of the loop instead of after it you can use continue
instead of break
.
A command you could loop over is
sed -n '23s/[^0-9]*([0-9]*)[^0-9]*/1+1000/p'
b2bsoapinput.xml | bc | xargs -I sed -i
'23s/([^0-9]*)[0-9]*([^0-9]*)/12/g' b2bsoapinput.xml
So you could run
for i in 1..25; do
curl -H "text/xml" --data-binary
"@/home/miracle/email/b2bsoapinput.xml"
https://x.x.x.x:5550 --insecure -u admin:xxxxx
>> somaoutput$i.xml || break
sed -n '23s/[^0-9]*([0-9]*)[^0-9]*/1+1000/p'
b2bsoapinput.xml | bc | xargs -I
sed -i '23s/([^0-9]*)[0-9]*([^0-9]*)/12/g'
b2bsoapinput.xml
done
The first sed
matches the only number in line 23 and replaces it with number+1000
. The .../p
tells sed to print the replaced value and -n
tells it to not print the changed file. Hence only the replacement string is piped on to bc
wich does the aritmetics. The second sed replaces the only number in line 23 with the new value and changes the file in place. I used xargs to put the piped value into the sed argument. The -I
sets the string that is replaced by the piped value to .
Edit: I added a || break
in the loop. This causes the loop to "stop" if the preseeding command fails (returns an exit code other than 0) and the program to continue after the loop. However, if curl does exit with 0 even when it receives an error response you need to call break
on another condition. Maybe something like grep "an error text" somaoutput$i.xml && break
.
If you want your program to continue with the next iteration of the loop instead of after it you can use continue
instead of break
.
edited Mar 5 at 9:47
answered Mar 1 at 11:13
katoshkatosh
1619
1619
It is my pleasure :)
– katosh
Mar 1 at 12:01
Hello Katosh, for above code I have to check a condition before looping the increments depends on the response code. Lets say we have a response at 22nd request as "request exceeds the limit" then it should stop increments and executes next command.
– harishchowdary
Mar 4 at 19:10
So you want to skip the number if curl fails?
– katosh
Mar 4 at 19:16
yes, and also need to do the same calls for 4 different servers
– harishchowdary
Mar 4 at 19:19
In your questions, you stated the number in the downloaded file should always be incremented by 1000. No matter what that number is. If you want to have curl retry until it succeeds I could edit that in my answer. What exactly should happen when it fails?
– katosh
Mar 4 at 19:39
|
show 2 more comments
It is my pleasure :)
– katosh
Mar 1 at 12:01
Hello Katosh, for above code I have to check a condition before looping the increments depends on the response code. Lets say we have a response at 22nd request as "request exceeds the limit" then it should stop increments and executes next command.
– harishchowdary
Mar 4 at 19:10
So you want to skip the number if curl fails?
– katosh
Mar 4 at 19:16
yes, and also need to do the same calls for 4 different servers
– harishchowdary
Mar 4 at 19:19
In your questions, you stated the number in the downloaded file should always be incremented by 1000. No matter what that number is. If you want to have curl retry until it succeeds I could edit that in my answer. What exactly should happen when it fails?
– katosh
Mar 4 at 19:39
It is my pleasure :)
– katosh
Mar 1 at 12:01
It is my pleasure :)
– katosh
Mar 1 at 12:01
Hello Katosh, for above code I have to check a condition before looping the increments depends on the response code. Lets say we have a response at 22nd request as "request exceeds the limit" then it should stop increments and executes next command.
– harishchowdary
Mar 4 at 19:10
Hello Katosh, for above code I have to check a condition before looping the increments depends on the response code. Lets say we have a response at 22nd request as "request exceeds the limit" then it should stop increments and executes next command.
– harishchowdary
Mar 4 at 19:10
So you want to skip the number if curl fails?
– katosh
Mar 4 at 19:16
So you want to skip the number if curl fails?
– katosh
Mar 4 at 19:16
yes, and also need to do the same calls for 4 different servers
– harishchowdary
Mar 4 at 19:19
yes, and also need to do the same calls for 4 different servers
– harishchowdary
Mar 4 at 19:19
In your questions, you stated the number in the downloaded file should always be incremented by 1000. No matter what that number is. If you want to have curl retry until it succeeds I could edit that in my answer. What exactly should happen when it fails?
– katosh
Mar 4 at 19:39
In your questions, you stated the number in the downloaded file should always be incremented by 1000. No matter what that number is. If you want to have curl retry until it succeeds I could edit that in my answer. What exactly should happen when it fails?
– katosh
Mar 4 at 19:39
|
show 2 more comments
Do like this, its basic loop
#!/bin/bash
for i in 1..25; do
# put the code you want to loop 25 times here
done
Or oneline:
$ for i in 1..25; do #your code here ; done
To increment values and substitute them, try this:
!/bin/bash
counter=1
for i in 1..25; do
# Send CURL request
curl -H "text/xml" --data-binary
"@/home/miracle/email/b2bsoapinput.xml"
https://x.x.x.x:5550 --insecure -u admin:xxxxx
>> somaoutput$i.xml
# inc_counter will hold values 1000 bigger than counter
# we will replace value of counter with inc_counter in text file
inc_counter=$(expr $counter + 1000)
# replace values
sed -i "23s/$counter/$inc_counter/g" b2soapinput.xml
# Increment counter by 1000
let "counter+=1000"
done
Thank You for this. But how about replacing the incremented values with 1000 starting from 1 to 25001
– harishchowdary
Mar 1 at 11:34
@harishchowdary i edited the answer
– Tryna Learn Somethin
Mar 1 at 11:56
Thank you....What if I want to loop and increment the count by 1000 based on the curl response?
– harishchowdary
Mar 5 at 9:29
This is gonna start from 1 and with each request in text file will substitute the value with the one that is 1000 greater
– Tryna Learn Somethin
Mar 5 at 10:07
yes I understand, but I want the loop to be incremented based on the curl response. Means I want to validate the response, upon that needs to increment the loop
– harishchowdary
Mar 5 at 10:27
add a comment |
Do like this, its basic loop
#!/bin/bash
for i in 1..25; do
# put the code you want to loop 25 times here
done
Or oneline:
$ for i in 1..25; do #your code here ; done
To increment values and substitute them, try this:
!/bin/bash
counter=1
for i in 1..25; do
# Send CURL request
curl -H "text/xml" --data-binary
"@/home/miracle/email/b2bsoapinput.xml"
https://x.x.x.x:5550 --insecure -u admin:xxxxx
>> somaoutput$i.xml
# inc_counter will hold values 1000 bigger than counter
# we will replace value of counter with inc_counter in text file
inc_counter=$(expr $counter + 1000)
# replace values
sed -i "23s/$counter/$inc_counter/g" b2soapinput.xml
# Increment counter by 1000
let "counter+=1000"
done
Thank You for this. But how about replacing the incremented values with 1000 starting from 1 to 25001
– harishchowdary
Mar 1 at 11:34
@harishchowdary i edited the answer
– Tryna Learn Somethin
Mar 1 at 11:56
Thank you....What if I want to loop and increment the count by 1000 based on the curl response?
– harishchowdary
Mar 5 at 9:29
This is gonna start from 1 and with each request in text file will substitute the value with the one that is 1000 greater
– Tryna Learn Somethin
Mar 5 at 10:07
yes I understand, but I want the loop to be incremented based on the curl response. Means I want to validate the response, upon that needs to increment the loop
– harishchowdary
Mar 5 at 10:27
add a comment |
Do like this, its basic loop
#!/bin/bash
for i in 1..25; do
# put the code you want to loop 25 times here
done
Or oneline:
$ for i in 1..25; do #your code here ; done
To increment values and substitute them, try this:
!/bin/bash
counter=1
for i in 1..25; do
# Send CURL request
curl -H "text/xml" --data-binary
"@/home/miracle/email/b2bsoapinput.xml"
https://x.x.x.x:5550 --insecure -u admin:xxxxx
>> somaoutput$i.xml
# inc_counter will hold values 1000 bigger than counter
# we will replace value of counter with inc_counter in text file
inc_counter=$(expr $counter + 1000)
# replace values
sed -i "23s/$counter/$inc_counter/g" b2soapinput.xml
# Increment counter by 1000
let "counter+=1000"
done
Do like this, its basic loop
#!/bin/bash
for i in 1..25; do
# put the code you want to loop 25 times here
done
Or oneline:
$ for i in 1..25; do #your code here ; done
To increment values and substitute them, try this:
!/bin/bash
counter=1
for i in 1..25; do
# Send CURL request
curl -H "text/xml" --data-binary
"@/home/miracle/email/b2bsoapinput.xml"
https://x.x.x.x:5550 --insecure -u admin:xxxxx
>> somaoutput$i.xml
# inc_counter will hold values 1000 bigger than counter
# we will replace value of counter with inc_counter in text file
inc_counter=$(expr $counter + 1000)
# replace values
sed -i "23s/$counter/$inc_counter/g" b2soapinput.xml
# Increment counter by 1000
let "counter+=1000"
done
edited Mar 1 at 11:56
answered Mar 1 at 11:04
Tryna Learn SomethinTryna Learn Somethin
1094
1094
Thank You for this. But how about replacing the incremented values with 1000 starting from 1 to 25001
– harishchowdary
Mar 1 at 11:34
@harishchowdary i edited the answer
– Tryna Learn Somethin
Mar 1 at 11:56
Thank you....What if I want to loop and increment the count by 1000 based on the curl response?
– harishchowdary
Mar 5 at 9:29
This is gonna start from 1 and with each request in text file will substitute the value with the one that is 1000 greater
– Tryna Learn Somethin
Mar 5 at 10:07
yes I understand, but I want the loop to be incremented based on the curl response. Means I want to validate the response, upon that needs to increment the loop
– harishchowdary
Mar 5 at 10:27
add a comment |
Thank You for this. But how about replacing the incremented values with 1000 starting from 1 to 25001
– harishchowdary
Mar 1 at 11:34
@harishchowdary i edited the answer
– Tryna Learn Somethin
Mar 1 at 11:56
Thank you....What if I want to loop and increment the count by 1000 based on the curl response?
– harishchowdary
Mar 5 at 9:29
This is gonna start from 1 and with each request in text file will substitute the value with the one that is 1000 greater
– Tryna Learn Somethin
Mar 5 at 10:07
yes I understand, but I want the loop to be incremented based on the curl response. Means I want to validate the response, upon that needs to increment the loop
– harishchowdary
Mar 5 at 10:27
Thank You for this. But how about replacing the incremented values with 1000 starting from 1 to 25001
– harishchowdary
Mar 1 at 11:34
Thank You for this. But how about replacing the incremented values with 1000 starting from 1 to 25001
– harishchowdary
Mar 1 at 11:34
@harishchowdary i edited the answer
– Tryna Learn Somethin
Mar 1 at 11:56
@harishchowdary i edited the answer
– Tryna Learn Somethin
Mar 1 at 11:56
Thank you....What if I want to loop and increment the count by 1000 based on the curl response?
– harishchowdary
Mar 5 at 9:29
Thank you....What if I want to loop and increment the count by 1000 based on the curl response?
– harishchowdary
Mar 5 at 9:29
This is gonna start from 1 and with each request in text file will substitute the value with the one that is 1000 greater
– Tryna Learn Somethin
Mar 5 at 10:07
This is gonna start from 1 and with each request in text file will substitute the value with the one that is 1000 greater
– Tryna Learn Somethin
Mar 5 at 10:07
yes I understand, but I want the loop to be incremented based on the curl response. Means I want to validate the response, upon that needs to increment the loop
– harishchowdary
Mar 5 at 10:27
yes I understand, but I want the loop to be incremented based on the curl response. Means I want to validate the response, upon that needs to increment the loop
– harishchowdary
Mar 5 at 10:27
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f503738%2flooping-by-replacing-the-values-in-a-file-and-then-doing-curl-request-for-25-tim%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown