Identify when curl command has finished successfully

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











up vote
0
down vote

favorite












I have a script which using a curl command to send a request to a web service, the output of the web service is written to a file.
The file is then moved to another location.



Instead of using a delay in the script (to wait for the completion of writing the output to a file) is there any way to identify whether the curl command has finished successfully and the output has been written to a file?



I want to avoid a scenario when I'm moving the file while information is still being written to it.



Appreciate your input










share|improve this question





















  • Why would you even think of using a delay?  Are you running curl in the background? If not, just put the mv command on the next line, or after a ; (or, better yet, &&).
    – Scott
    Oct 2 '17 at 4:55














up vote
0
down vote

favorite












I have a script which using a curl command to send a request to a web service, the output of the web service is written to a file.
The file is then moved to another location.



Instead of using a delay in the script (to wait for the completion of writing the output to a file) is there any way to identify whether the curl command has finished successfully and the output has been written to a file?



I want to avoid a scenario when I'm moving the file while information is still being written to it.



Appreciate your input










share|improve this question





















  • Why would you even think of using a delay?  Are you running curl in the background? If not, just put the mv command on the next line, or after a ; (or, better yet, &&).
    – Scott
    Oct 2 '17 at 4:55












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a script which using a curl command to send a request to a web service, the output of the web service is written to a file.
The file is then moved to another location.



Instead of using a delay in the script (to wait for the completion of writing the output to a file) is there any way to identify whether the curl command has finished successfully and the output has been written to a file?



I want to avoid a scenario when I'm moving the file while information is still being written to it.



Appreciate your input










share|improve this question













I have a script which using a curl command to send a request to a web service, the output of the web service is written to a file.
The file is then moved to another location.



Instead of using a delay in the script (to wait for the completion of writing the output to a file) is there any way to identify whether the curl command has finished successfully and the output has been written to a file?



I want to avoid a scenario when I'm moving the file while information is still being written to it.



Appreciate your input







bash curl






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 2 '17 at 4:28









Borka

11




11











  • Why would you even think of using a delay?  Are you running curl in the background? If not, just put the mv command on the next line, or after a ; (or, better yet, &&).
    – Scott
    Oct 2 '17 at 4:55
















  • Why would you even think of using a delay?  Are you running curl in the background? If not, just put the mv command on the next line, or after a ; (or, better yet, &&).
    – Scott
    Oct 2 '17 at 4:55















Why would you even think of using a delay?  Are you running curl in the background? If not, just put the mv command on the next line, or after a ; (or, better yet, &&).
– Scott
Oct 2 '17 at 4:55




Why would you even think of using a delay?  Are you running curl in the background? If not, just put the mv command on the next line, or after a ; (or, better yet, &&).
– Scott
Oct 2 '17 at 4:55










2 Answers
2






active

oldest

votes

















up vote
2
down vote













Why would you be using a delay, and why would you need to move the file?



Just write the file in the correct place to start with:



curl -o /path/to/correct/place/filename URL


Curl exits with a zero exit status if it terminates without error. You may use this fact to move the file into the correct location only when Curl is successful:



curl -o file URL && mv file /some/place


Or, if you need to do some error reporting:



if curl -o file URL; then
mv file /some/place
# or, to use sftp:
# printf 'put filen' | sftp -b - user@host
else
printf 'Curl failed with error code "%d" (check the manual)n' "$?" >&2
exit 1
fi





share|improve this answer






















  • Thanks for your input. I see that using a delay is not the way to go. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
    – Borka
    Oct 2 '17 at 9:34











  • @Borka See the comments in the last bit of code.
    – Kusalananda
    Oct 2 '17 at 10:09

















up vote
0
down vote













Use && for curl and mv command. in this case mv will execute only if previous curl command was executed successfully.



curl .... >to_file && mv to_file /to/dest


If you need to move file across sftp server, use below command.



sftp USER@HOST:/path/in/remote/dest <<< $'put /path/to/local/to_file'


Or even directly write in remote sftp path the FILE curl will output.



sftp USER@HOST:/path/in/remote/dest <<< $'put /path/to/local/"$(curl -o FILE URL)"'





share|improve this answer






















  • Thanks for your input. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
    – Borka
    Oct 2 '17 at 9:43










  • please check my updated answer.
    – Î±Ò“sнιη
    Oct 2 '17 at 9:52










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%2f395558%2fidentify-when-curl-command-has-finished-successfully%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













Why would you be using a delay, and why would you need to move the file?



Just write the file in the correct place to start with:



curl -o /path/to/correct/place/filename URL


Curl exits with a zero exit status if it terminates without error. You may use this fact to move the file into the correct location only when Curl is successful:



curl -o file URL && mv file /some/place


Or, if you need to do some error reporting:



if curl -o file URL; then
mv file /some/place
# or, to use sftp:
# printf 'put filen' | sftp -b - user@host
else
printf 'Curl failed with error code "%d" (check the manual)n' "$?" >&2
exit 1
fi





share|improve this answer






















  • Thanks for your input. I see that using a delay is not the way to go. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
    – Borka
    Oct 2 '17 at 9:34











  • @Borka See the comments in the last bit of code.
    – Kusalananda
    Oct 2 '17 at 10:09














up vote
2
down vote













Why would you be using a delay, and why would you need to move the file?



Just write the file in the correct place to start with:



curl -o /path/to/correct/place/filename URL


Curl exits with a zero exit status if it terminates without error. You may use this fact to move the file into the correct location only when Curl is successful:



curl -o file URL && mv file /some/place


Or, if you need to do some error reporting:



if curl -o file URL; then
mv file /some/place
# or, to use sftp:
# printf 'put filen' | sftp -b - user@host
else
printf 'Curl failed with error code "%d" (check the manual)n' "$?" >&2
exit 1
fi





share|improve this answer






















  • Thanks for your input. I see that using a delay is not the way to go. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
    – Borka
    Oct 2 '17 at 9:34











  • @Borka See the comments in the last bit of code.
    – Kusalananda
    Oct 2 '17 at 10:09












up vote
2
down vote










up vote
2
down vote









Why would you be using a delay, and why would you need to move the file?



Just write the file in the correct place to start with:



curl -o /path/to/correct/place/filename URL


Curl exits with a zero exit status if it terminates without error. You may use this fact to move the file into the correct location only when Curl is successful:



curl -o file URL && mv file /some/place


Or, if you need to do some error reporting:



if curl -o file URL; then
mv file /some/place
# or, to use sftp:
# printf 'put filen' | sftp -b - user@host
else
printf 'Curl failed with error code "%d" (check the manual)n' "$?" >&2
exit 1
fi





share|improve this answer














Why would you be using a delay, and why would you need to move the file?



Just write the file in the correct place to start with:



curl -o /path/to/correct/place/filename URL


Curl exits with a zero exit status if it terminates without error. You may use this fact to move the file into the correct location only when Curl is successful:



curl -o file URL && mv file /some/place


Or, if you need to do some error reporting:



if curl -o file URL; then
mv file /some/place
# or, to use sftp:
# printf 'put filen' | sftp -b - user@host
else
printf 'Curl failed with error code "%d" (check the manual)n' "$?" >&2
exit 1
fi






share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 2 '17 at 10:09

























answered Oct 2 '17 at 5:42









Kusalananda

105k14209326




105k14209326











  • Thanks for your input. I see that using a delay is not the way to go. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
    – Borka
    Oct 2 '17 at 9:34











  • @Borka See the comments in the last bit of code.
    – Kusalananda
    Oct 2 '17 at 10:09
















  • Thanks for your input. I see that using a delay is not the way to go. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
    – Borka
    Oct 2 '17 at 9:34











  • @Borka See the comments in the last bit of code.
    – Kusalananda
    Oct 2 '17 at 10:09















Thanks for your input. I see that using a delay is not the way to go. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
– Borka
Oct 2 '17 at 9:34





Thanks for your input. I see that using a delay is not the way to go. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
– Borka
Oct 2 '17 at 9:34













@Borka See the comments in the last bit of code.
– Kusalananda
Oct 2 '17 at 10:09




@Borka See the comments in the last bit of code.
– Kusalananda
Oct 2 '17 at 10:09












up vote
0
down vote













Use && for curl and mv command. in this case mv will execute only if previous curl command was executed successfully.



curl .... >to_file && mv to_file /to/dest


If you need to move file across sftp server, use below command.



sftp USER@HOST:/path/in/remote/dest <<< $'put /path/to/local/to_file'


Or even directly write in remote sftp path the FILE curl will output.



sftp USER@HOST:/path/in/remote/dest <<< $'put /path/to/local/"$(curl -o FILE URL)"'





share|improve this answer






















  • Thanks for your input. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
    – Borka
    Oct 2 '17 at 9:43










  • please check my updated answer.
    – Î±Ò“sнιη
    Oct 2 '17 at 9:52














up vote
0
down vote













Use && for curl and mv command. in this case mv will execute only if previous curl command was executed successfully.



curl .... >to_file && mv to_file /to/dest


If you need to move file across sftp server, use below command.



sftp USER@HOST:/path/in/remote/dest <<< $'put /path/to/local/to_file'


Or even directly write in remote sftp path the FILE curl will output.



sftp USER@HOST:/path/in/remote/dest <<< $'put /path/to/local/"$(curl -o FILE URL)"'





share|improve this answer






















  • Thanks for your input. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
    – Borka
    Oct 2 '17 at 9:43










  • please check my updated answer.
    – Î±Ò“sнιη
    Oct 2 '17 at 9:52












up vote
0
down vote










up vote
0
down vote









Use && for curl and mv command. in this case mv will execute only if previous curl command was executed successfully.



curl .... >to_file && mv to_file /to/dest


If you need to move file across sftp server, use below command.



sftp USER@HOST:/path/in/remote/dest <<< $'put /path/to/local/to_file'


Or even directly write in remote sftp path the FILE curl will output.



sftp USER@HOST:/path/in/remote/dest <<< $'put /path/to/local/"$(curl -o FILE URL)"'





share|improve this answer














Use && for curl and mv command. in this case mv will execute only if previous curl command was executed successfully.



curl .... >to_file && mv to_file /to/dest


If you need to move file across sftp server, use below command.



sftp USER@HOST:/path/in/remote/dest <<< $'put /path/to/local/to_file'


Or even directly write in remote sftp path the FILE curl will output.



sftp USER@HOST:/path/in/remote/dest <<< $'put /path/to/local/"$(curl -o FILE URL)"'






share|improve this answer














share|improve this answer



share|improve this answer








edited Oct 2 '17 at 10:56

























answered Oct 2 '17 at 4:45









αғsнιη

15.7k92563




15.7k92563











  • Thanks for your input. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
    – Borka
    Oct 2 '17 at 9:43










  • please check my updated answer.
    – Î±Ò“sнιη
    Oct 2 '17 at 9:52
















  • Thanks for your input. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
    – Borka
    Oct 2 '17 at 9:43










  • please check my updated answer.
    – Î±Ò“sнιη
    Oct 2 '17 at 9:52















Thanks for your input. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
– Borka
Oct 2 '17 at 9:43




Thanks for your input. I need to move/copy the file to a sftp (public key authentication is in place). Any idea what approach would be best to use?
– Borka
Oct 2 '17 at 9:43












please check my updated answer.
– Î±Ò“sнιη
Oct 2 '17 at 9:52




please check my updated answer.
– Î±Ò“sнιη
Oct 2 '17 at 9:52

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395558%2fidentify-when-curl-command-has-finished-successfully%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?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay