摘要
某用户在一段时间登录linux系统并且删除、创建文件,或者修改文件属性,这些操作现在可以由管理员账户查看到吗?
不是仅仅知道用户何时登录过,还能看出来他的具体操作。
感觉有点意思,有空再看看。因为有点零散(主要是三人),所以改转载为抄自。
No.1
export PROMPT_COMMAND='{
date "+: %c; `history 1 | { read x cmd; echo "$cmd"; }`";
} >;>; $HOME/.history-timestamp’
某用户在一段时间登录linux系统并且删除、创建文件,或者修改文件属性,这些操作现在可以由管理员账户查看到吗?
不是仅仅知道用户何时登录过,还能看出来他的具体操作。
感觉有点意思,有空再看看。因为有点零散(主要是三人),所以改转载为抄自。
No.1
export PROMPT_COMMAND='{
date "+: %c; `history 1 | { read x cmd; echo "$cmd"; }`";
} >;>; $HOME/.history-timestamp'
或者安装 Bash 3.0
http://ftp.gnu.org/gnu/bash/bash-3.0.tar.gz
bb. New HISTTIMEFORMAT variable; value is a format string to pass to
strftime(3). If set and not null, the `history' builtin prints out
timestamp information according to the specified format when displaying
history entries. If set, bash tells the history library to write out
timestamp information when the history file is written.
或者用Snare for Linux大炮打苍蝇
No.2
试了有个楼主给的PROMPT_COMMAND,总是有问题。自己就写了个麻烦点的。
把他们加到.bashrc文件中, source .bashrc 即可。
# === Begin ====
datestamp_history(){
export infodate=`date "+: %c"`
export infohis=`history 1`
echo $infodate' =>; '$infohis >;>; $HOME/.history-timestamp
}
export PROMPT_COMMAND=datestamp_history
# === end =====
No.3
export PROMPT_COMMAND='{ z=$(history 1 | { read x y; echo $y; }); echo -n $(date "+%c") :: $z ::; who am i; } >> $HOME/.history-timestamp'