注册登录记录通过linux脚本进行记录,Linux 用户登录后操作记录脚本

linux 用户登录系统后操作记录脚本,虽然我们可以查阅日志或者history来获取相关信息。

这里我介绍一种比较直观方便的方法也能达到预期的效果,如有不足之处,望大侠们给予建议。

# vi /etc/profile.d/accountlog.sh

historyLog(){

logDir=/opt/accountlog

dateStamp=`date +"[%F %T]"`

dateDir="`date +%Y`/`date +%m`/`date +%d`"

curHistory=`history 1`

user=`/usr/bin/whoami`

realUserInfor=`/usr/bin/who -u am i|awk '{print $1,$2,$3"~"$4,$7}'`

if [ ! -e $logDir ];then

mkdir -p $logDir

chmod 777 $logDir

fi

logDateDir=$logDir/$dateDir

if [ ! -e $logDateDir ];then

mkdir -p $logDateDir

chmod -R 777 $logDir 2>/dev/null

fi

accountLogDir=$logDateDir/${user:=`hostname`}

if [ ! -e $accountLogDir ];then

mkdir -p $accountLogDir

#chmod 777 $accountLogDir

fi

accountLogName=${user:=`hostname`}.his

accountLog=$accountLogDir/$accountLogName

if [ ! -e "$accountLog" ];then

touch $accountLog

#chmod 777 $accountLog

fi

echo "$realUserInfor $dateStamp =>$curHistory" >>$accountLog

}

export PROMPT_COMMAND=historyLog

#chmod +x /etc/profile.d/accountlog.sh

以后每个用户登录的操作都会在/opt/accountlog记录。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值