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..ie, get every shell command I type to trigger a "dump that command into a file" part. Any ideas?
Thanks
In bash, the PROMPT_COMMAND
environment variable contains a command that will be executed before the PS1
prompt is displayed. So yours could be something like history | tail -n1 | perl -npe 's/^\\s+\\d+\\s+//' | yourcommand HOST
history | tail -n1 | perl -npe 's/^\\s+\\d+\\s+//' | yourcommand HOST
The script
utility should solve your problem. It records everything you type and all that is printed on the terminal in a file (even including terminal control codes, so if you cat
that file on the console, you even reproduce the original text colors).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.