Google
Edit File: lw-history-bash.sh
#!/bin/bash ############################# ## DO NOT MODIFY THIS FILE ## ## CHANGES ARE OVERWRITTEN ## ############################# if [[ "$0" == *jailshell ]]; then return 0 fi export LW_HIST_USERIP= export LW_HIST_USER= export LW_HIST_PWD= # LW_HIST_USERIP="${LW_HIST_USERIP:-}" # LW_HIST_USER="${LW_HIST_USER:-}" # LW_HIST_PWD="${LW_HIST_PWD:-}" function lw_hist_write() { myUser="$(id -nu)" if [[ -z "${myUser}" ]]; then myUser="unknown" fi # if it matches, write the history line # note we do this to skip the first command run by that user if [[ "${LW_HIST_USER}" == "${myUser}" ]]; then # actually write the history OLD_HISTTIMEFORMAT="${HISTTIMEFORMAT}" # history format to use HISTTIMEFORMAT="%Y-%m-%d %T %z ${LW_HIST_USER}@${LW_HIST_USERIP}:${LW_HIST_PWD} " # write that line of history history 1 >>/usr/local/lp/logs/history.log #restore anything else set HISTTIMEFORMAT="${OLD_HISTTIMEFORMAT}" fi LW_HIST_USERIP="$(awk '{print $1}' <<<"${SSH_CLIENT}")" LW_HIST_USER="${myUser}" LW_HIST_PWD="${PWD}" } # if we're not set up for writing history, set it up # write our history then write bash history before every prompt # also, you do want PROMPT_COMMAND not PS1 - see https://tldp.org/HOWTO/Bash-Prompt-HOWTO/x264.html # if [[ -z "${PROMPT_COMMAND}" || "${PROMPT_COMMAND}" != *lw_hist_write* ]]; then if [[ "${PROMPT_COMMAND}" != *lw_hist_write* ]]; then set -o histexpand PROMPT_COMMAND="lw_hist_write; ${PROMPT_COMMAND}" fi