I know history will capture commands that I run, but it is shell specific. I work with multiple shells and multiple hosts and would like to write a small script which, after every command I run, dumps that command to some file along with the host name. This way, i can implement my own history command which reads from that file, and can take a host as an argument which would be handy for me. I’m not sure how to get the first part though..i.e., get every shell command I type to trigger a “dump that command into a file” part. Any ideas?
Thanks
In bash, the
PROMPT_COMMANDenvironment variable contains a command that will be executed before thePS1prompt is displayed. So yours could be something likehistory | tail -n1 | perl -npe 's/^\s+\d+\s+//' | yourcommand HOST