码迷,mamicode.com
首页 > 其他好文 > 详细

history命令显示出详细时间

时间:2016-06-06 10:33:27      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

文章摘自:

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 <<EOF>>/etc/profile
    #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
 

history命令显示出详细时间

标签:

原文地址:http://www.cnblogs.com/smail-bao/p/5562815.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!