Silent failure adding user to group
As part of an environment setup script we have the following snippet which installs docker:
if [ ! "$(docker -v)" ]; then
infoMessage "Setting up Docker..."
echo "Updating system packages.."
sudo apt-get update
echo "Installing dependencies..."
sudo apt -y install apt-transport-https ca-certificates curl software-properties-common
echo "Adding GPG key..."
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
echo "Adding docker repository..."
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-cache policy docker-ce
echo "Installing docker engine..."
sudo apt-get -y install docker.ce
sudo usermod -aG docker ${USER}
newgrp docker
fi
However for two of our devs for some reason the script silently exits just after installing docker and before the fi
(found this with echo
's). Either the usermod
or newgrp
command. Exit code is zero and I'm completely stumped as to why this is happening consistently on only their machines which should be functionally identical to others, apart from any personal configs and changes they've made. When they ran the commands individually there were no issues at all and they could then re-run the script to finish setup.
I've checked breakline characters, they're LF (n) the same as everywhere else in the script. They're running Ubuntu 18.04.
shell-script ubuntu docker group
add a comment |
As part of an environment setup script we have the following snippet which installs docker:
if [ ! "$(docker -v)" ]; then
infoMessage "Setting up Docker..."
echo "Updating system packages.."
sudo apt-get update
echo "Installing dependencies..."
sudo apt -y install apt-transport-https ca-certificates curl software-properties-common
echo "Adding GPG key..."
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
echo "Adding docker repository..."
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-cache policy docker-ce
echo "Installing docker engine..."
sudo apt-get -y install docker.ce
sudo usermod -aG docker ${USER}
newgrp docker
fi
However for two of our devs for some reason the script silently exits just after installing docker and before the fi
(found this with echo
's). Either the usermod
or newgrp
command. Exit code is zero and I'm completely stumped as to why this is happening consistently on only their machines which should be functionally identical to others, apart from any personal configs and changes they've made. When they ran the commands individually there were no issues at all and they could then re-run the script to finish setup.
I've checked breakline characters, they're LF (n) the same as everywhere else in the script. They're running Ubuntu 18.04.
shell-script ubuntu docker group
Possibly slightly different PATHs? Personally, I would put the absolute path to each command or utility in this tyoe of script.
– fpmurphy
Nov 6 at 15:43
I'm not sure what you mean @fpmurphy1usermod
andnewgrp
are fairly standard and they definitely have the commands working on their machines as entering those two lines into the terminal works no problem.
– Shard
Nov 6 at 15:56
Update: I've recently upgraded my machine with a fresh install, ubuntu 16 -> ubuntu 18. Now I get the issue too, I find it likely that this is an issue relating to the distro version.
– Shard
Dec 4 at 12:23
The failure is due to newgrp, which I want to use to log the user into the newly created group
– Shard
Dec 17 at 11:29
add a comment |
As part of an environment setup script we have the following snippet which installs docker:
if [ ! "$(docker -v)" ]; then
infoMessage "Setting up Docker..."
echo "Updating system packages.."
sudo apt-get update
echo "Installing dependencies..."
sudo apt -y install apt-transport-https ca-certificates curl software-properties-common
echo "Adding GPG key..."
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
echo "Adding docker repository..."
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-cache policy docker-ce
echo "Installing docker engine..."
sudo apt-get -y install docker.ce
sudo usermod -aG docker ${USER}
newgrp docker
fi
However for two of our devs for some reason the script silently exits just after installing docker and before the fi
(found this with echo
's). Either the usermod
or newgrp
command. Exit code is zero and I'm completely stumped as to why this is happening consistently on only their machines which should be functionally identical to others, apart from any personal configs and changes they've made. When they ran the commands individually there were no issues at all and they could then re-run the script to finish setup.
I've checked breakline characters, they're LF (n) the same as everywhere else in the script. They're running Ubuntu 18.04.
shell-script ubuntu docker group
As part of an environment setup script we have the following snippet which installs docker:
if [ ! "$(docker -v)" ]; then
infoMessage "Setting up Docker..."
echo "Updating system packages.."
sudo apt-get update
echo "Installing dependencies..."
sudo apt -y install apt-transport-https ca-certificates curl software-properties-common
echo "Adding GPG key..."
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
echo "Adding docker repository..."
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-cache policy docker-ce
echo "Installing docker engine..."
sudo apt-get -y install docker.ce
sudo usermod -aG docker ${USER}
newgrp docker
fi
However for two of our devs for some reason the script silently exits just after installing docker and before the fi
(found this with echo
's). Either the usermod
or newgrp
command. Exit code is zero and I'm completely stumped as to why this is happening consistently on only their machines which should be functionally identical to others, apart from any personal configs and changes they've made. When they ran the commands individually there were no issues at all and they could then re-run the script to finish setup.
I've checked breakline characters, they're LF (n) the same as everywhere else in the script. They're running Ubuntu 18.04.
shell-script ubuntu docker group
shell-script ubuntu docker group
edited Nov 6 at 13:17
Jeff Schaller
38.7k1053125
38.7k1053125
asked Nov 6 at 11:46
Shard
1116
1116
Possibly slightly different PATHs? Personally, I would put the absolute path to each command or utility in this tyoe of script.
– fpmurphy
Nov 6 at 15:43
I'm not sure what you mean @fpmurphy1usermod
andnewgrp
are fairly standard and they definitely have the commands working on their machines as entering those two lines into the terminal works no problem.
– Shard
Nov 6 at 15:56
Update: I've recently upgraded my machine with a fresh install, ubuntu 16 -> ubuntu 18. Now I get the issue too, I find it likely that this is an issue relating to the distro version.
– Shard
Dec 4 at 12:23
The failure is due to newgrp, which I want to use to log the user into the newly created group
– Shard
Dec 17 at 11:29
add a comment |
Possibly slightly different PATHs? Personally, I would put the absolute path to each command or utility in this tyoe of script.
– fpmurphy
Nov 6 at 15:43
I'm not sure what you mean @fpmurphy1usermod
andnewgrp
are fairly standard and they definitely have the commands working on their machines as entering those two lines into the terminal works no problem.
– Shard
Nov 6 at 15:56
Update: I've recently upgraded my machine with a fresh install, ubuntu 16 -> ubuntu 18. Now I get the issue too, I find it likely that this is an issue relating to the distro version.
– Shard
Dec 4 at 12:23
The failure is due to newgrp, which I want to use to log the user into the newly created group
– Shard
Dec 17 at 11:29
Possibly slightly different PATHs? Personally, I would put the absolute path to each command or utility in this tyoe of script.
– fpmurphy
Nov 6 at 15:43
Possibly slightly different PATHs? Personally, I would put the absolute path to each command or utility in this tyoe of script.
– fpmurphy
Nov 6 at 15:43
I'm not sure what you mean @fpmurphy1
usermod
and newgrp
are fairly standard and they definitely have the commands working on their machines as entering those two lines into the terminal works no problem.– Shard
Nov 6 at 15:56
I'm not sure what you mean @fpmurphy1
usermod
and newgrp
are fairly standard and they definitely have the commands working on their machines as entering those two lines into the terminal works no problem.– Shard
Nov 6 at 15:56
Update: I've recently upgraded my machine with a fresh install, ubuntu 16 -> ubuntu 18. Now I get the issue too, I find it likely that this is an issue relating to the distro version.
– Shard
Dec 4 at 12:23
Update: I've recently upgraded my machine with a fresh install, ubuntu 16 -> ubuntu 18. Now I get the issue too, I find it likely that this is an issue relating to the distro version.
– Shard
Dec 4 at 12:23
The failure is due to newgrp, which I want to use to log the user into the newly created group
– Shard
Dec 17 at 11:29
The failure is due to newgrp, which I want to use to log the user into the newly created group
– Shard
Dec 17 at 11:29
add a comment |
1 Answer
1
active
oldest
votes
The reason is that newgrp
is essentially just creating a new bash instance and as a result until it exits (never happens) it cant continue execution of the script. Essentially the same as if you had su - $(id -u -n);
in your script
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%2f480097%2fsilent-failure-adding-user-to-group%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The reason is that newgrp
is essentially just creating a new bash instance and as a result until it exits (never happens) it cant continue execution of the script. Essentially the same as if you had su - $(id -u -n);
in your script
add a comment |
The reason is that newgrp
is essentially just creating a new bash instance and as a result until it exits (never happens) it cant continue execution of the script. Essentially the same as if you had su - $(id -u -n);
in your script
add a comment |
The reason is that newgrp
is essentially just creating a new bash instance and as a result until it exits (never happens) it cant continue execution of the script. Essentially the same as if you had su - $(id -u -n);
in your script
The reason is that newgrp
is essentially just creating a new bash instance and as a result until it exits (never happens) it cant continue execution of the script. Essentially the same as if you had su - $(id -u -n);
in your script
answered Dec 17 at 11:37
Shard
1116
1116
add a comment |
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.
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%2funix.stackexchange.com%2fquestions%2f480097%2fsilent-failure-adding-user-to-group%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
Possibly slightly different PATHs? Personally, I would put the absolute path to each command or utility in this tyoe of script.
– fpmurphy
Nov 6 at 15:43
I'm not sure what you mean @fpmurphy1
usermod
andnewgrp
are fairly standard and they definitely have the commands working on their machines as entering those two lines into the terminal works no problem.– Shard
Nov 6 at 15:56
Update: I've recently upgraded my machine with a fresh install, ubuntu 16 -> ubuntu 18. Now I get the issue too, I find it likely that this is an issue relating to the distro version.
– Shard
Dec 4 at 12:23
The failure is due to newgrp, which I want to use to log the user into the newly created group
– Shard
Dec 17 at 11:29