Identify when curl command has finished successfully
Clash 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
bash curl
add a comment |Â
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
bash curl
Why would you even think of using a delay?â Are you running curl in the background?âÂÂIf not, just put themv
command on the next line, or after a;
(or, better yet,&&
).
â Scott
Oct 2 '17 at 4:55
add a comment |Â
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
bash curl
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
bash curl
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 themv
command on the next line, or after a;
(or, better yet,&&
).
â Scott
Oct 2 '17 at 4:55
add a comment |Â
Why would you even think of using a delay?â Are you running curl in the background?âÂÂIf not, just put themv
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
add a comment |Â
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
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
add a comment |Â
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)"'
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
add a comment |Â
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
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
add a comment |Â
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
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
add a comment |Â
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
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
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
add a comment |Â
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
add a comment |Â
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)"'
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
add a comment |Â
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)"'
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
add a comment |Â
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)"'
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)"'
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
add a comment |Â
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
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%2f395558%2fidentify-when-curl-command-has-finished-successfully%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
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