文章摘自:
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
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