Created
November 20, 2017 07:00
-
-
Save PSJoshi/f3e20a586847708838e2f2b28a0d6a71 to your computer and use it in GitHub Desktop.
Send bash history to syslog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Increase history size | |
export HISTSIZE=5000 | |
# In the command below - every time a new prompt is issued (ie whenever you get through running a command), first the history is appended to the file, then it is cleared from the current shell's memory, then the current shell reloads the history from the file. | |
#export PROMPT_COMMAND="history -a; history -c; history -r; ${PROMPT_COMMAND}" | |
It is easy to export bash commands to syslog which can be centralized and analyzed. | |
Add the following lines to bashrc. | |
[root@psj]# vim /etc/bashrc | |
PROMPT_COMMAND=$(history -a) | |
typeset -r PROMPT_COMMAND | |
function log2syslog | |
{ | |
declare command | |
command=$BASH_COMMAND | |
logger -p local1.notice -t bash -i -- "$USER : $PWD : $command" | |
} | |
trap log2syslog DEBUG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment