Ending slogin session with exit command freezes due to PROMPT_COMMAND modification
I recently embedded an "alert" command into my PROMPT_COMMAND to give me a little notify-send screen notification with the exit code of each command (because I always forget to append the alert when a long-running job is started).
That works like a charm, but then I discovered a minor nuisance about it:
When I connect to another computer in my network via slogin and want to disconnect with exit, it states "logout" and then just sits there.
When I press [ctrl]+[c] it is back to my local session without a problem.
I figured out that if I chuck out the "auto-alert" in all SSH-sessions the problem disappears. It's not that big of a deal, but I just wonder what is happening and maybe how to fix it, if possible.
Here's the command (in my aliases):
alias alert='notify-send --urgency=low -i "$([ $? -eq 0 ] && echo terminal || echo error)" "$(history 1|sed -e '''s/^s*[0-9]+s*//;s/[;&|]s*alert$//''')"'
And this is in my .bashrc:
if [[ "$PROMPT_COMMAND" != alert* ]]; then # && ([ -z "$SSH_CLIENT" ] || [ -z "$SSH_TTY" ]); then
PROMPT_COMMAND="alert; $PROMPT_COMMAND"
fi
If i add the comment to the line (remove ; then #), the slogin session exits immediately without a problem (but also doesn't notify me of long-running jobs ending, of course).
ssh alias bashrc exit
add a comment |
I recently embedded an "alert" command into my PROMPT_COMMAND to give me a little notify-send screen notification with the exit code of each command (because I always forget to append the alert when a long-running job is started).
That works like a charm, but then I discovered a minor nuisance about it:
When I connect to another computer in my network via slogin and want to disconnect with exit, it states "logout" and then just sits there.
When I press [ctrl]+[c] it is back to my local session without a problem.
I figured out that if I chuck out the "auto-alert" in all SSH-sessions the problem disappears. It's not that big of a deal, but I just wonder what is happening and maybe how to fix it, if possible.
Here's the command (in my aliases):
alias alert='notify-send --urgency=low -i "$([ $? -eq 0 ] && echo terminal || echo error)" "$(history 1|sed -e '''s/^s*[0-9]+s*//;s/[;&|]s*alert$//''')"'
And this is in my .bashrc:
if [[ "$PROMPT_COMMAND" != alert* ]]; then # && ([ -z "$SSH_CLIENT" ] || [ -z "$SSH_TTY" ]); then
PROMPT_COMMAND="alert; $PROMPT_COMMAND"
fi
If i add the comment to the line (remove ; then #), the slogin session exits immediately without a problem (but also doesn't notify me of long-running jobs ending, of course).
ssh alias bashrc exit
A marginal comment on your first code section: you could advantageously replacehistory | tail -n1withhistory 1, I think. Also if you are testing arithmetic values in bash, go for[ $? -eq 0 ]or if you test on strings, go for:[ "$?" == "0" ]. In the latter form a single=sign is also accepted. Mixing things up is a good recipe for issues.
– Cbhihe
Dec 18 at 17:09
@Cbhihe Thanks for the suggestions, I edited the script for these two minor "issues". Had not even thought about "history 1", very neat. Sadly, both changes had no effect on the logout procedure..
– BUFU
Dec 19 at 10:10
add a comment |
I recently embedded an "alert" command into my PROMPT_COMMAND to give me a little notify-send screen notification with the exit code of each command (because I always forget to append the alert when a long-running job is started).
That works like a charm, but then I discovered a minor nuisance about it:
When I connect to another computer in my network via slogin and want to disconnect with exit, it states "logout" and then just sits there.
When I press [ctrl]+[c] it is back to my local session without a problem.
I figured out that if I chuck out the "auto-alert" in all SSH-sessions the problem disappears. It's not that big of a deal, but I just wonder what is happening and maybe how to fix it, if possible.
Here's the command (in my aliases):
alias alert='notify-send --urgency=low -i "$([ $? -eq 0 ] && echo terminal || echo error)" "$(history 1|sed -e '''s/^s*[0-9]+s*//;s/[;&|]s*alert$//''')"'
And this is in my .bashrc:
if [[ "$PROMPT_COMMAND" != alert* ]]; then # && ([ -z "$SSH_CLIENT" ] || [ -z "$SSH_TTY" ]); then
PROMPT_COMMAND="alert; $PROMPT_COMMAND"
fi
If i add the comment to the line (remove ; then #), the slogin session exits immediately without a problem (but also doesn't notify me of long-running jobs ending, of course).
ssh alias bashrc exit
I recently embedded an "alert" command into my PROMPT_COMMAND to give me a little notify-send screen notification with the exit code of each command (because I always forget to append the alert when a long-running job is started).
That works like a charm, but then I discovered a minor nuisance about it:
When I connect to another computer in my network via slogin and want to disconnect with exit, it states "logout" and then just sits there.
When I press [ctrl]+[c] it is back to my local session without a problem.
I figured out that if I chuck out the "auto-alert" in all SSH-sessions the problem disappears. It's not that big of a deal, but I just wonder what is happening and maybe how to fix it, if possible.
Here's the command (in my aliases):
alias alert='notify-send --urgency=low -i "$([ $? -eq 0 ] && echo terminal || echo error)" "$(history 1|sed -e '''s/^s*[0-9]+s*//;s/[;&|]s*alert$//''')"'
And this is in my .bashrc:
if [[ "$PROMPT_COMMAND" != alert* ]]; then # && ([ -z "$SSH_CLIENT" ] || [ -z "$SSH_TTY" ]); then
PROMPT_COMMAND="alert; $PROMPT_COMMAND"
fi
If i add the comment to the line (remove ; then #), the slogin session exits immediately without a problem (but also doesn't notify me of long-running jobs ending, of course).
ssh alias bashrc exit
ssh alias bashrc exit
edited Dec 19 at 10:05
asked Dec 18 at 9:38
BUFU
163
163
A marginal comment on your first code section: you could advantageously replacehistory | tail -n1withhistory 1, I think. Also if you are testing arithmetic values in bash, go for[ $? -eq 0 ]or if you test on strings, go for:[ "$?" == "0" ]. In the latter form a single=sign is also accepted. Mixing things up is a good recipe for issues.
– Cbhihe
Dec 18 at 17:09
@Cbhihe Thanks for the suggestions, I edited the script for these two minor "issues". Had not even thought about "history 1", very neat. Sadly, both changes had no effect on the logout procedure..
– BUFU
Dec 19 at 10:10
add a comment |
A marginal comment on your first code section: you could advantageously replacehistory | tail -n1withhistory 1, I think. Also if you are testing arithmetic values in bash, go for[ $? -eq 0 ]or if you test on strings, go for:[ "$?" == "0" ]. In the latter form a single=sign is also accepted. Mixing things up is a good recipe for issues.
– Cbhihe
Dec 18 at 17:09
@Cbhihe Thanks for the suggestions, I edited the script for these two minor "issues". Had not even thought about "history 1", very neat. Sadly, both changes had no effect on the logout procedure..
– BUFU
Dec 19 at 10:10
A marginal comment on your first code section: you could advantageously replace
history | tail -n1 with history 1, I think. Also if you are testing arithmetic values in bash, go for [ $? -eq 0 ] or if you test on strings, go for: [ "$?" == "0" ] . In the latter form a single = sign is also accepted. Mixing things up is a good recipe for issues.– Cbhihe
Dec 18 at 17:09
A marginal comment on your first code section: you could advantageously replace
history | tail -n1 with history 1, I think. Also if you are testing arithmetic values in bash, go for [ $? -eq 0 ] or if you test on strings, go for: [ "$?" == "0" ] . In the latter form a single = sign is also accepted. Mixing things up is a good recipe for issues.– Cbhihe
Dec 18 at 17:09
@Cbhihe Thanks for the suggestions, I edited the script for these two minor "issues". Had not even thought about "history 1", very neat. Sadly, both changes had no effect on the logout procedure..
– BUFU
Dec 19 at 10:10
@Cbhihe Thanks for the suggestions, I edited the script for these two minor "issues". Had not even thought about "history 1", very neat. Sadly, both changes had no effect on the logout procedure..
– BUFU
Dec 19 at 10:10
add a comment |
active
oldest
votes
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%2f489644%2fending-slogin-session-with-exit-command-freezes-due-to-prompt-command-modificati%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f489644%2fending-slogin-session-with-exit-command-freezes-due-to-prompt-command-modificati%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
A marginal comment on your first code section: you could advantageously replace
history | tail -n1withhistory 1, I think. Also if you are testing arithmetic values in bash, go for[ $? -eq 0 ]or if you test on strings, go for:[ "$?" == "0" ]. In the latter form a single=sign is also accepted. Mixing things up is a good recipe for issues.– Cbhihe
Dec 18 at 17:09
@Cbhihe Thanks for the suggestions, I edited the script for these two minor "issues". Had not even thought about "history 1", very neat. Sadly, both changes had no effect on the logout procedure..
– BUFU
Dec 19 at 10:10