linux 历史记录命令
命令方式
#/bin/bash #cd /tmp saveFile="tmp.log" isok="`grep HISTTIMEFORMAT /etc/profile|wc -l`" if [ $isok -eq 0 ] thenecho -e "#history time\nHISTFILESIZE=4000\nHISTSIZE=4000\nHISTTIMEFORMAT='%F %T '\nexport HISTTIMEFORMAT\n" >>${saveFile} fiisok="`grep PROMPT_COMMAND /etc/profile|wc -l`" if [ $isok -eq 0 ] thenecho -e "#log to messages\nexport PROMPT_COMMAND='{ msg=\$(history 1 | { read x y; echo \$y; });logger \"[euid=\$(whoami)]\":\$(who am i):[\`pwd\`]\"\$msg\"; }'" >>${saveFile} fi
在机器 /etc/profile 里加上:
#history time
HISTFILESIZE=4000
HISTSIZE=4000
HISTTIMEFORMAT='%F %T '
export HISTTIMEFORMAT
#log to messages
export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg"; }'
export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[euid=$(whoami)]":$(who am i):[`pwd`]"$msg"; }'