zoukankan      html  css  js  c++  java
  • Linux server record All user's ops

    append to /etc/profile
    root@moonx:/tmp/dbasky/moonx# cat /etc/profile

      USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
      if [ "$USER_IP" = "" ]
      then
      USER_IP=`hostname`
      fi
      export HISTTIMEFORMAT="%F %T $USER_IP:`whoami` "

    append to /etc/profile
    root@moonx:/tmp/dbasky/moonx# cat /etc/profile
    ...
    PS1="`whoami`@`hostname`:"'[$PWD]'
    history
    USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
    if [ "$USER_IP" = "" ]
    then
    USER_IP=`hostname`
    fi
    if [ ! -d /tmp/dbasky ]
    then
    mkdir /tmp/dbasky
    chmod 777 /tmp/dbasky
    fi
    if [ ! -d /tmp/dbasky/${LOGNAME} ]
    then
    mkdir /tmp/dbasky/${LOGNAME}
    chmod 300 /tmp/dbasky/${LOGNAME}
    fi
    export HISTSIZE=4096
    DT=`date "+%Y-%m-%d_%H:%M:%S"`
    export HISTFILE="/tmp/dbasky/${LOGNAME}/${USER_IP} dbasky.$DT"
    chmod 600 /tmp/dbasky/${LOGNAME}/*dbasky* 2>/dev/null
    moonx@moonx:/tmp/dbasky$ sudo -i
    root@moonx:~# cd /tmp/dbasky/moonx/
    root@moonx:/tmp/dbasky/moonx# ls
    192.168.5.45 dbasky.2019-11-22_11:37:27
    192.168.5.45 dbasky.2019-11-22_11:41:55
    root@moonx:/tmp/dbasky/moonx# cat 192.168.5.45 dbasky.2019-11-22_11:41:55 
    ls
    echo $HISTFILE
    cat /etc/profile
    root@moonx:/tmp/dbasky/moonx#
  • 相关阅读:
    The first appliaction for "Hello World!"
    zone
    learn to study
    深入理解 Angular 2 变化监测和 ngZone
    看看吧
    生命周期钩子
    一个简单的todo
    依赖注入
    @Output()
    @Input
  • 原文地址:https://www.cnblogs.com/cjyp/p/11937087.html
Copyright © 2011-2022 走看看