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/^[ \t]*//g' |cut -d " " -f2-)";) >> $file
} 2>/dev/null

相关文章:

  • 2021-12-13
  • 2022-12-23
  • 2021-07-26
  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2022-01-10
  • 2021-06-23
  • 2021-11-13
  • 2021-12-24
相关资源
相似解决方案