linux命令执行记录

ssh执行命令记录

/etc/profile添加

readonly PROMPT_COMMAND=/opt/bin/operation_record.sh 

/opt/bin/operation_record.sh

{
if [ ! -d /var/log/operation ]
then
mkdir /var/log/operation
if [ `id -u` -eq 0 ]
then
chattr +a /var/log/operation
fi
fi

file=/var/log/operation/`date '+%y-%m-%d'`.log
if [ ! -f $file ]
then
touch $file
chmod 777 $file
fi

echo $(date "+%y-%m-%d %T ## $(who am i |awk "{print $1" "$2" "$5}") ## $(pwd) ## $(history 1 | sed 's/^[ ]*//g' |cut -d " " -f2-)";) >> $file
} 2>/dev/null

原文地址:https://www.cnblogs.com/banwhui/p/4597690.html