0

How can I make sure that my bash history gets written to ~/.bash_history when I am disconnected abnormally?

I work on several remote Linux hosts, and my connection is frequently terminated abnormally. When that happens, my recent bash history is not available when I reconnect. I suspect that the abnormal termination is preventing the bash shell from writing to ~/.bash_history. I can't control the disconnects, and other than losing my history, the abnormal disconnects don't cause a problem.

I don't want to interfere with the normal history mechanism. In other words, I don't want a hack that messes up the history process. Thanks!

EDIT:

I am concerned about the ~/.bash_history on the remote machine.

The immediate write method may be the best way to go. The abnormal termination event may not allow a final dump to ~/.bash_history.

I have keep alive set up for ssh, but the remote hosts don't always allow that.

wdb
  • 115
  • 1
  • 6
  • which `~/.bash_history` do you mean, in the remote machines or in your current host? – kenn Jun 03 '20 at 17:45
  • 3
    Does this answer your question? [Is it possible to make writing to .bash\_history immediate?](https://askubuntu.com/questions/67283/is-it-possible-to-make-writing-to-bash-history-immediate) – EchoMike444 Jun 03 '20 at 18:15
  • Yes @EchoMike444. That does answer my question. – wdb Jun 04 '20 at 17:01

0 Answers0