When I reboot my server over SSH, the session just hangs instead of nicely logging me out, so that I can continue to use the current terminal.
I tried the following to fix this: https://bbs.archlinux.org/viewtopic.php?id=50089
But then my bash history isn't saved before rebooting.
Is there a way to nicely log out all users (so that their bash history is saved) before a reboot/halt command? i.e. save bash history and end user sessions before reboot/halt?
OS: Ubuntu Server 11.04
Best Answer
You need to execute something like
history -a
in each user session. I can't think of a "nice" way to do this but using PROMPT_COMMAND in bash would work, PROMPT_COMMAND is an env variable for a command that is execute every time bash returns to a prompt, i.e. it automatically flushes the history to .bash_history on each command execute. Works but probably not the best solution. Put this in the.bashrc
or in a profile.d file (if you are on profile.d compatible distro).