zoukankan      html  css  js  c++  java
  • 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
     
  • 相关阅读:
    前端每周学习分享--第7期
    前端每周学习分享--第5期
    博客迁移声明
    使用Angular CLI创建Angular 2项目
    使用Gulp压缩CSS/JS
    [JS]继承方式总结
    [JS]算法总结
    圆梦之旅 – 日本(一)攻略篇
    新年畅想
    [CSS]三栏自适应布局
  • 原文地址:https://www.cnblogs.com/smail-bao/p/5562815.html
Copyright © 2011-2022 走看看