You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
794 B
31 lines
794 B
2 years ago
|
#!/usr/bin/env bash
|
||
|
#history
|
||
|
|
||
|
# 获取登录ip地址
|
||
|
# USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
|
||
|
USER_IP=$(env |grep SSH_CLIENT | awk '{print $1}' | sed 's/SSH_CLIENT=//' | awk -F " " '{print $1}')
|
||
|
# 指定历史命令路径
|
||
|
HISTDIR=/usr/share/.history
|
||
|
if [ -z $USER_IP ]
|
||
|
then
|
||
|
USER_IP=`hostname`
|
||
|
fi
|
||
|
if [ ! -d $HISTDIR ]
|
||
|
then
|
||
|
mkdir -p $HISTDIR
|
||
|
chmod 777 $HISTDIR
|
||
|
fi
|
||
|
if [ ! -d $HISTDIR/${LOGNAME} ]
|
||
|
then
|
||
|
mkdir -p $HISTDIR/${LOGNAME}
|
||
|
chmod 300 $HISTDIR/${LOGNAME}
|
||
|
fi
|
||
|
# 设置历史命令条数
|
||
|
export HISTSIZE=4000
|
||
|
# 设置文件后缀
|
||
|
DT=`date +%Y%m%d_%H%M%S`
|
||
|
export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.history.$DT" #文件路径
|
||
|
export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S] " #记录格式
|
||
|
# 设置权限
|
||
|
chmod 600 $HISTDIR/${LOGNAME}/*.history* 2>/dev/null
|