How can I get `apt-get update` to reflect error status in its exit code?
When running sudo apt-get update -q
, sometimes I see things like
Err:23 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu precise/main i386 Packages
Could not connect to ppa.launchpad.net:80 (91.189.95.83), connection timed out
Err:24 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu precise/main Translation-en
Unable to connect to ppa.launchpad.net:http:
or like
W: http://us-central1.gce.archive.ubuntu.com/ubuntu/dists/precise-updates/InRelease: Signature by key 630239CC130E1A7FD81A27B140976EAF437D05B5 uses weak digest algorithm (SHA1)
But echo $?
tells me that apt-get update -q
succeeded. How can I get the error/warning status to be fatal, and make apt-get update
fail with a non-zero exit code?
apt updates error-handling aptitude
add a comment |
When running sudo apt-get update -q
, sometimes I see things like
Err:23 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu precise/main i386 Packages
Could not connect to ppa.launchpad.net:80 (91.189.95.83), connection timed out
Err:24 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu precise/main Translation-en
Unable to connect to ppa.launchpad.net:http:
or like
W: http://us-central1.gce.archive.ubuntu.com/ubuntu/dists/precise-updates/InRelease: Signature by key 630239CC130E1A7FD81A27B140976EAF437D05B5 uses weak digest algorithm (SHA1)
But echo $?
tells me that apt-get update -q
succeeded. How can I get the error/warning status to be fatal, and make apt-get update
fail with a non-zero exit code?
apt updates error-handling aptitude
1
Hmmmm, if I run it with an error myecho $?
returns100
. Without errors it returns0
.
– Terrance
Jan 16 '18 at 16:54
Hmmm, maybe I was misreading the travis logs I was looking at... What about when there are warnings?
– Jason Gross
Jan 16 '18 at 21:40
1
Look at unix.stackexchange.com/questions/175146/… in the answer there is a little script that could detect both W: and E:. But when I did theapt update -q
with just warnings, I got0
on theecho $?
. But the script passed and got both errors and warnings.
– Terrance
Jan 16 '18 at 22:18
add a comment |
When running sudo apt-get update -q
, sometimes I see things like
Err:23 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu precise/main i386 Packages
Could not connect to ppa.launchpad.net:80 (91.189.95.83), connection timed out
Err:24 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu precise/main Translation-en
Unable to connect to ppa.launchpad.net:http:
or like
W: http://us-central1.gce.archive.ubuntu.com/ubuntu/dists/precise-updates/InRelease: Signature by key 630239CC130E1A7FD81A27B140976EAF437D05B5 uses weak digest algorithm (SHA1)
But echo $?
tells me that apt-get update -q
succeeded. How can I get the error/warning status to be fatal, and make apt-get update
fail with a non-zero exit code?
apt updates error-handling aptitude
When running sudo apt-get update -q
, sometimes I see things like
Err:23 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu precise/main i386 Packages
Could not connect to ppa.launchpad.net:80 (91.189.95.83), connection timed out
Err:24 http://ppa.launchpad.net/chris-lea/redis-server/ubuntu precise/main Translation-en
Unable to connect to ppa.launchpad.net:http:
or like
W: http://us-central1.gce.archive.ubuntu.com/ubuntu/dists/precise-updates/InRelease: Signature by key 630239CC130E1A7FD81A27B140976EAF437D05B5 uses weak digest algorithm (SHA1)
But echo $?
tells me that apt-get update -q
succeeded. How can I get the error/warning status to be fatal, and make apt-get update
fail with a non-zero exit code?
apt updates error-handling aptitude
apt updates error-handling aptitude
asked Jan 16 '18 at 16:41
Jason Gross
1034
1034
1
Hmmmm, if I run it with an error myecho $?
returns100
. Without errors it returns0
.
– Terrance
Jan 16 '18 at 16:54
Hmmm, maybe I was misreading the travis logs I was looking at... What about when there are warnings?
– Jason Gross
Jan 16 '18 at 21:40
1
Look at unix.stackexchange.com/questions/175146/… in the answer there is a little script that could detect both W: and E:. But when I did theapt update -q
with just warnings, I got0
on theecho $?
. But the script passed and got both errors and warnings.
– Terrance
Jan 16 '18 at 22:18
add a comment |
1
Hmmmm, if I run it with an error myecho $?
returns100
. Without errors it returns0
.
– Terrance
Jan 16 '18 at 16:54
Hmmm, maybe I was misreading the travis logs I was looking at... What about when there are warnings?
– Jason Gross
Jan 16 '18 at 21:40
1
Look at unix.stackexchange.com/questions/175146/… in the answer there is a little script that could detect both W: and E:. But when I did theapt update -q
with just warnings, I got0
on theecho $?
. But the script passed and got both errors and warnings.
– Terrance
Jan 16 '18 at 22:18
1
1
Hmmmm, if I run it with an error my
echo $?
returns 100
. Without errors it returns 0
.– Terrance
Jan 16 '18 at 16:54
Hmmmm, if I run it with an error my
echo $?
returns 100
. Without errors it returns 0
.– Terrance
Jan 16 '18 at 16:54
Hmmm, maybe I was misreading the travis logs I was looking at... What about when there are warnings?
– Jason Gross
Jan 16 '18 at 21:40
Hmmm, maybe I was misreading the travis logs I was looking at... What about when there are warnings?
– Jason Gross
Jan 16 '18 at 21:40
1
1
Look at unix.stackexchange.com/questions/175146/… in the answer there is a little script that could detect both W: and E:. But when I did the
apt update -q
with just warnings, I got 0
on the echo $?
. But the script passed and got both errors and warnings.– Terrance
Jan 16 '18 at 22:18
Look at unix.stackexchange.com/questions/175146/… in the answer there is a little script that could detect both W: and E:. But when I did the
apt update -q
with just warnings, I got 0
on the echo $?
. But the script passed and got both errors and warnings.– Terrance
Jan 16 '18 at 22:18
add a comment |
2 Answers
2
active
oldest
votes
You could create a bash script that check the command output :
if { apt-get update 2>&1 || echo E: update failed; } > result.txt; cat result.txt | grep -q '^[(W)|(E]:'; then
echo error
else (
if cat result.txt | grep -q '^[(Get)]:'; then
echo repaired
else
echo success
fi
)
fi
Here, we check if a line start with E (Err: or E:, etc..) for errors or with W for warnings. Both return the status code error.
If there is no error and there is a Get:, it means that we update our repos. It returns the status code repaired.
And finally, if we havent encountered any of those, the script was a success.
add a comment |
As mentioned by @Terrance, this question is very close to that other question apt-get update exit status (in Unix & Linux StackExchange).
FYI I've just posted there another solution that can also be combined with the travis_retry
Travis CI command (which might be the intended use case of the OP):
exec {fd}>&2 # copy stderr to some unused fd
travis_retry bash -o pipefail -c "sudo apt-get update -y -q 2>&1 | tee /dev/fd/$fd | ( ! grep -q -e '^Err:' -e '^E:' )"
exec {fd}>&- # close file descriptor
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2faskubuntu.com%2fquestions%2f996665%2fhow-can-i-get-apt-get-update-to-reflect-error-status-in-its-exit-code%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
You could create a bash script that check the command output :
if { apt-get update 2>&1 || echo E: update failed; } > result.txt; cat result.txt | grep -q '^[(W)|(E]:'; then
echo error
else (
if cat result.txt | grep -q '^[(Get)]:'; then
echo repaired
else
echo success
fi
)
fi
Here, we check if a line start with E (Err: or E:, etc..) for errors or with W for warnings. Both return the status code error.
If there is no error and there is a Get:, it means that we update our repos. It returns the status code repaired.
And finally, if we havent encountered any of those, the script was a success.
add a comment |
You could create a bash script that check the command output :
if { apt-get update 2>&1 || echo E: update failed; } > result.txt; cat result.txt | grep -q '^[(W)|(E]:'; then
echo error
else (
if cat result.txt | grep -q '^[(Get)]:'; then
echo repaired
else
echo success
fi
)
fi
Here, we check if a line start with E (Err: or E:, etc..) for errors or with W for warnings. Both return the status code error.
If there is no error and there is a Get:, it means that we update our repos. It returns the status code repaired.
And finally, if we havent encountered any of those, the script was a success.
add a comment |
You could create a bash script that check the command output :
if { apt-get update 2>&1 || echo E: update failed; } > result.txt; cat result.txt | grep -q '^[(W)|(E]:'; then
echo error
else (
if cat result.txt | grep -q '^[(Get)]:'; then
echo repaired
else
echo success
fi
)
fi
Here, we check if a line start with E (Err: or E:, etc..) for errors or with W for warnings. Both return the status code error.
If there is no error and there is a Get:, it means that we update our repos. It returns the status code repaired.
And finally, if we havent encountered any of those, the script was a success.
You could create a bash script that check the command output :
if { apt-get update 2>&1 || echo E: update failed; } > result.txt; cat result.txt | grep -q '^[(W)|(E]:'; then
echo error
else (
if cat result.txt | grep -q '^[(Get)]:'; then
echo repaired
else
echo success
fi
)
fi
Here, we check if a line start with E (Err: or E:, etc..) for errors or with W for warnings. Both return the status code error.
If there is no error and there is a Get:, it means that we update our repos. It returns the status code repaired.
And finally, if we havent encountered any of those, the script was a success.
answered Apr 24 '18 at 14:31
Quentin Pétel
112
112
add a comment |
add a comment |
As mentioned by @Terrance, this question is very close to that other question apt-get update exit status (in Unix & Linux StackExchange).
FYI I've just posted there another solution that can also be combined with the travis_retry
Travis CI command (which might be the intended use case of the OP):
exec {fd}>&2 # copy stderr to some unused fd
travis_retry bash -o pipefail -c "sudo apt-get update -y -q 2>&1 | tee /dev/fd/$fd | ( ! grep -q -e '^Err:' -e '^E:' )"
exec {fd}>&- # close file descriptor
add a comment |
As mentioned by @Terrance, this question is very close to that other question apt-get update exit status (in Unix & Linux StackExchange).
FYI I've just posted there another solution that can also be combined with the travis_retry
Travis CI command (which might be the intended use case of the OP):
exec {fd}>&2 # copy stderr to some unused fd
travis_retry bash -o pipefail -c "sudo apt-get update -y -q 2>&1 | tee /dev/fd/$fd | ( ! grep -q -e '^Err:' -e '^E:' )"
exec {fd}>&- # close file descriptor
add a comment |
As mentioned by @Terrance, this question is very close to that other question apt-get update exit status (in Unix & Linux StackExchange).
FYI I've just posted there another solution that can also be combined with the travis_retry
Travis CI command (which might be the intended use case of the OP):
exec {fd}>&2 # copy stderr to some unused fd
travis_retry bash -o pipefail -c "sudo apt-get update -y -q 2>&1 | tee /dev/fd/$fd | ( ! grep -q -e '^Err:' -e '^E:' )"
exec {fd}>&- # close file descriptor
As mentioned by @Terrance, this question is very close to that other question apt-get update exit status (in Unix & Linux StackExchange).
FYI I've just posted there another solution that can also be combined with the travis_retry
Travis CI command (which might be the intended use case of the OP):
exec {fd}>&2 # copy stderr to some unused fd
travis_retry bash -o pipefail -c "sudo apt-get update -y -q 2>&1 | tee /dev/fd/$fd | ( ! grep -q -e '^Err:' -e '^E:' )"
exec {fd}>&- # close file descriptor
answered Aug 13 '18 at 12:53
ErikMD
1113
1113
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2faskubuntu.com%2fquestions%2f996665%2fhow-can-i-get-apt-get-update-to-reflect-error-status-in-its-exit-code%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
1
Hmmmm, if I run it with an error my
echo $?
returns100
. Without errors it returns0
.– Terrance
Jan 16 '18 at 16:54
Hmmm, maybe I was misreading the travis logs I was looking at... What about when there are warnings?
– Jason Gross
Jan 16 '18 at 21:40
1
Look at unix.stackexchange.com/questions/175146/… in the answer there is a little script that could detect both W: and E:. But when I did the
apt update -q
with just warnings, I got0
on theecho $?
. But the script passed and got both errors and warnings.– Terrance
Jan 16 '18 at 22:18