Sindbad~EG File Manager
| Current Path : /etc/profile.d/ |
|
|
| Current File : //etc/profile.d/sau_logging.sh |
# /etc/profile.d/sau_logging.sh
function logbash {
[[ $- != *i* ]] && return # Only interactive
[[ "$BASH_SUBSHELL" -ne 0 ]] && return # Not in subshell
[[ "$SHLVL" -gt 2 ]] && return # Avoid deep shells
# Get last command
local CMD=$(fc -ln -0 2>/dev/null)
[[ -z "$CMD" ]] && return
# Block problematic parents
local PARENT=$(ps -o comm= -p $PPID)
[[ "$PARENT" =~ (acronis|install|ansible|cron|systemd) ]] && return
# Log only from the oldest bash attached to this TTY
local TTY=$(tty)
local OLDEST_BASH_PID=$(ps -t "$TTY" -o pid=,comm= --sort=start_time | awk '$2 == "bash" { print $1; exit }')
[[ "$$" -ne "$OLDEST_BASH_PID" ]] && return
logger -p local1.notice -t bash -i "$USER[$PWD]@${SSH_CLIENT%% *}:$CMD"
}
[[ $- == *i* ]] && trap logbash DEBUG
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists