I want to be able to setup a MySQL database and record all commands issued on my server by username and command. Is this possible, and if so, how would I set it up?
play with PROMPT_COMMAND if you want this in real-time (each line),
this could be something like:
PROMPT_COMMAND='echo mysql -c "INSERT $(history 1|sed "s/^ *[0-9]* *//")"'
this could be stored in your $HOME/.bashrc.
play with $HOME/.bash_logout if you prefer digest at each logout.
this could let you begin your own script, try adding something like this to your .profile
if [ "$HISTFILE" ] ;then
export HISTFILE=$(mktemp $HOME/.bash_history_XXXXXXXX)
cat >>"$OHISTFILE" "$HISTFILE"
mysql -c "INSERT ... $(<$HISTFILE).."
Sign up using Google
Sign up using Facebook
Sign up using Stack Exchange
By posting your answer, you agree to the
terms of service.
5 months ago