领导让做个脚本,大概意思就是每天检查下系统中的几个常用的文件,检查是否做过变更,然后把日志发成邮件出来。
所以先写脚本了,脚本其实很简单,大概就是先把文件备份出来,然后下次运行的时候,diff两个文件,写到日志里即可。于是就写了一个,除了可以检查文件的变更,也可以检查某些命令输出的变更,还有shell文件输出的变更。
脚本很简单,见笑了。
View Code
#Subject:detect changes from command/file/shell#Author:zhaofei#Version:1.0 2013.1.23#History:None#file_list="/etc/fstab /etc/passwd"cmd_list="mount"shell_list="computer_item.sh"shell_root='/script/test'date >> $shell_root/changes.logfor i in $file_listdo file_name=$(echo $i | sed 's/.*\///g') cp $i $shell_root/$file_name.new echo $file_name >> $shell_root/changes.log diff $shell_root/$file_name.new $shell_root/$file_name.old >> $shell_root/changes.log cp $shell_root/$file_name.new $shell_root/$file_name.old rm $shell_root/$file_name.newdonefor j in $cmd_listdo $j 1>$shell_root/$j.new echo $j >> $shell_root/changes.log diff $shell_root/$j.new $shell_root/$j.old >> $shell_root/changes.log cp $shell_root/$j.new $shell_root/$j.old rm $shell_root/$j.newdonefor k in $shell_listdo sh $shell_root/$k > $shell_root/$k.new echo $k >> $shell_root/changes.log diff $shell_root/$k.new $shell_root/$k.old >> $shell_root/changes.log cp $shell_root/$k.new $shell_root/$k.old rm $shell_root/$k.newdone