Ubuntu命令审计,记录Bash命令

in PHP with 0 comment
#Record history operation
USER_IP=`who -u am i 2>/dev/null |awk '{print $NF}' |sed -e 's/[()]//g'`
LOG_NAME=`who -u am i |awk '{print $1}'`
HIST_DIR=/var/log/.history
if [ -z ${USER_IP} ]
then
    USER_IP=`hostname`
fi

if [ ! -d ${HIST_DIR} ]
then
    mkdir -p ${HIST_DIR}
    chmod 777 ${HIST_DIR}
fi

if [ ! -d ${HIST_DIR}/${LOG_NAME} ]
then
    mkdir -p ${HIST_DIR}/${LOG_NAME}
    chmod 300 ${HIST_DIR}/${LOG_NAME}
fi

export HISTSIZE=4000
export HISTFILESIZE=4000
export HISTTIMEFORMAT="[%F %T] "

DT=`date +"%Y%m%d_%H%M%S"`
export HISTFILE="${HIST_DIR}/${LOG_NAME}/${USER_IP}.history.$DT"
chmod 600 ${HIST_DIR}/${LOG_NAME}/*.history* 2>/dev/null

将上述命令放到profile文件。

Comments are closed.