Take a look at the project Bashhub. It's effectively exactly what you are asking for - a dropbox for bash history - but they have added tools to reference the history from all your machines, assuming they have access to the internet. There are valid concerns about sending your shell interactions to a third party (e.g. employer, privacy, working on sensitive material), but if those aren't a significant factor this seems like a great solution. It doesn't appear they have open sourced the server component of the code, unfortunately, which would be nice to mitigate the previously mentioned issues.
There are a bunch of less sophisticated techniques that you can use, particularly if each machine has ssh access to each other, or at least each can talk to one central server via ssh. Any solution that involves multiple machines that could be in use simultaneously updating a common history file (either in a single linked location or in distributed updates) will somewhat break the history expansion capabilities of bash - e.g. recalling the last command with !! could get you the wrong command. These are just some ideas that would need to be fleshed out some:
- Configure an NFS share from a server, mount on each machine, sym link your .bash_history file from it
Use the bash PROMPT_COMMAND capability to append a remote file with your last command ( e.g in .bashrc PROMPT_COMMAND="append_history"
then add the function append_history () { ( ssh you@yourserver "echo !! >> ~/common_bash_history" ) & }
. I put the ssh command in a subshell and backgrounded it to remove the delay after entering a command. You would then have to periodically push the changes from the common_bash_history file to each machine (Only adding unique entries).
Periodic cron job that runs on one of the machines ('server') that pulls the histories from each, creates a master and pushes it out.
In my case Bashhub wouldn't work, for reasons mentioned above. I've been looking for a 'perfect' solution to this and haven't found it - what I have settled on for the time being is aggregating all of my histories from each machine into a master history file on one server. But I don't push the aggregated results back into each machine's history file; I use a separate file for this, which lets me add things like which machine it came from to it, and I set up new search and completion functions for the aggregate file (which I use for 'long term' history) and leaving bashs history expansion / completion intact (which I use for 'short term' history). If bashhub made the server software available as well as the client software it would be a highly polished alternative of the solution (hack) I've thrown together.
~/.bash_history
? No DropBox, no external, no need of internet connection but only the needs required for the shared folder. (ps> else you can always manually copy the file ...). Or you can take the file from the host via ssh with a script in cron....