SHARE
TWEET

Bash History Logger

h8rt3rmin8r Jun 1st, 2020 1,280 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2. #>
  3. #> [ cmd.sh ]
  4. #>
  5. #>    Export an environment variable that enables command line logging
  6. #>
  7. #>    Created on 20200601 by h8rt3rmin8r
  8. #>
  9. #> REFERENCE:
  10. #>
  11. #>    https://spin.atomicobject.com/2016/05/28/log-bash-history/
  12. #>
  13.  
  14. export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then _PCDTX=$(date "+%s%N"); _PCDIR="/home/${USER}/.logs/bash-history"; _PCFIL="${_PCDIR}/${_PCDTX:0:4}.log"; _PCHST="$(history 1 | sed '"'s/^\ *//;s/\ /|/;s/\ /\$> /'"')"; mkdir -p "${_PCDIR}"; echo "${_PCDTX}|${PWD}|${_PCHST}" >> "${_PCFIL}"; fi'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top