In my .bashrc
I have already added:
# https://stackoverflow.com/a/40158199/9881330
function rescue_history {
history -a
}
trap rescue_history SIGHUP
However, this does not work, because after client_loop: send disconnect: Connection reset by peer
the history is still lost. Which is very annoying since the useful entered commands are all lost!
The core question: How to configure .bashrc
to save the history when ssh connection is reset by peer?
Very confused that this "history saving" behavior is not enabled by default.
My .bashrc
also has also this (if it might help):
# new history settings
# http://jesrui.sdf-eu.org/remember-all-your-bash-history-forever.html
HISTTIMEFORMAT='%F %T '
HISTFILESIZE=-1
HISTSIZE=-1
HISTCONTROL=ignoredups
#HISTIGNORE=?:?? # lines with one or two characters are discarded from the history (e.g. ls commands)
shopt -s histappend # append to history, don't overwrite it
# attempt to save all lines of a multiple-line command in the same history entry
shopt -s cmdhist
# save multi-line commands to the history with embedded newlines
shopt -s lithist
PROMPT_COMMAND
to save history after each command instead storing it in the memory and dumping it to the file when exiting which is the default behavior.