• history命令显示出详细时间


    文章摘自:

    http://blog.csdn.net/lixiaohuiok111/article/details/34428161

     
     
    首先我们给opt的目录赋予写的权限
    sudo chmod a+w /opt
     
    然后执行source /etc/profile 
     
    然后退出机器的时候,再次进入的时候  /opt/history下面就会有文件产生
    admin.history
     
    然后我们再把相应的权限改回来
     
    写成脚本使用ansible批量部署到其他的机器上
    • #!/bin/bash
      sudo chmod a+w /opt
      cat >>/etc/profile <<EOF
      #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 /opt/history ]
      then
      mkdir /opt/history
      chmod 777 /opt/history
      fi
      if [ ! -d /opt/history/${LOGNAME} ]
      then
      mkdir /opt/history/${LOGNAME}
      chmod 300 /opt/history/${LOGNAME}
      fi
      export HISTSIZE=4096
      export HISTTIMEFORMAT="%F %T $USER_IP:\`whoami\` "
      export HISTFILE="/opt/history/${LOGNAME}.history"
      chmod 600 /opt/history/*history* 2>/dev/null
      EOF
      source /etc/profile
      sudo chmod o-w /opt

     
     
    #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 /opt/history ]
    then
    mkdir /opt/history
    chmod 777 /opt/history
    fi
    if [ ! -d /opt/history/${LOGNAME} ]
    then
    mkdir /opt/history/${LOGNAME}
    chmod 300 /opt/history/${LOGNAME}
    fi
    export HISTSIZE=4096
    export HISTTIMEFORMAT="%F %T $USER_IP:`whoami` "
    export HISTFILE="/opt/history/${LOGNAME}.history"
    chmod 600 /opt/history/*history* 2>/dev/null
     
  • 相关阅读:
    jQuery 在 IE 上 clone checkbox 的問題。
    C/C++ typedef用法
    C++继承
    map常用操作
    C++ JsonCpp 使用(含源码下载)
    string常用操作
    C++虚函数
    STL容器迭代过程中删除元素技巧(转)
    关于IE下用HTTPS无法下载/打开文件(转)
    C++STL概览
  • 原文地址:https://www.cnblogs.com/smail-bao/p/5562815.html
Copyright © 2020-2023  润新知