- 论坛徽章:
- 0
|
怎样记录删除操作的相关信息?
...
可以这样子,写一个脚本,比如说取名叫 log, 放到 $PATH 中去,
- #!/bin/sh
- LOG=/var/log`date +%Y%m%d`.log
- echo \"
- ===========================================================
- DATE: `date`
- USER: $LOGNAME
- EXEC: $@ \" >;>; $LOG 2>; /dev/null
- $@ 2>;&1 | tee -a $LOG
复制代码
然后,在 .profile 中用
alias rm=\'log rm\'
alias mv=\'log mv\'
alias rmdir=\'log rmdir\'
...
等等,alias 所有你想记录的命令,这样子,生成每天的记录(当然你也可以只用一个),其结果就是生成如下格式的日志
- ===========================================================
- DATE: Sat Mar 28 21:54:31 MET 2003
- USER: sleeve
- EXEC: rm c
- ===========================================================
- DATE: Sat Mar 28 21:55:59 MET 2003
- USER: sleeve
- EXEC: rmdir ddd
- rmdir: directory \"ddd\": Path component not a directory
- ===========================================================
- DATE: Sat Mar 28 21:56:25 MET 2003
- USER: sleeve
- EXEC: rm ttt
- ttt: No such file or directory
- ===========================================================
- DATE: Sat Mar 28 21:56:31 MET 2003
- USER: sleeve
- EXEC: rm ccc
- rm: ccc is a directory
- ===========================================================
- DATE: Sat Mar 28 21:56:41 MET 2003
- USER: sleeve
- EXEC: rmdir ccc
- rmdir: directory \"ccc\": Directory not empty
- ===========================================================
- DATE: Sat Mar 28 21:56:45 MET 2003
- USER: sleeve
- EXEC: rm -rf ccc
- ===========================================================
- DATE: Sat Mar 28 21:56:49 MET 2003
- USER: sleeve
- EXEC: rm a.gif b.gif c.gif d.gif e.gif
复制代码
EXEC 下面没有 error message 的就是删除、移动成功的,而其它的则为有这样的企图但未成功。 |
|