用于管理其他用户的历史命令记录的方案:
编辑 /etc/profile

在 /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/.hist ]
then
mkdir /tmp/.hist
chmod 777 /tmp/.hist
fi
if [ ! -d /tmp/.hist/${LOGNAME} ]
then
mkdir /tmp/.hist/${LOGNAME}
chmod 300 /tmp/.hist/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date "+%Y%m%d_%H%M%S"`
export HISTFILE="/tmp/.hist/${LOGNAME}/${USER_IP}.hist.$DT"
chmod 600 /tmp/.hist/${LOGNAME}/*.hist* 2>/dev/null
添加完后如图所示:

source /etc/profile 使用脚本生效
退出用户登录,进入 /tmp/.hist/root 就可发现,如下图所示:
