• 检查Linux文件变更Shell脚本


    领导让做个脚本,大概意思就是每天检查下系统中的几个常用的文件,检查是否做过变更,然后把日志发成邮件出来。
    所以先写脚本了,脚本其实很简单,大概就是先把文件备份出来,然后下次运行的时候,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.log
    for i in $file_list
    do
            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.new
    done
    for j in $cmd_list
    do
            $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.new
    done
    for k in $shell_list
    do
            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.new
    done
  • 相关阅读:
    EasyUI dialog
    winform 收集
    ASP.NET文件下载,直接向客户端输出文件(转)
    反射收集
    Sql Server 2008 R2 备份数据库报错
    慎用Ext.QuickTip和Ext.QuickTips(转)
    使用正则Regex来移除网页的ViewState(转)
    mysql 实现远程链接(转)
    MySqlBackup.NET,C# mysql备份数据库
    Firefox下站长统计代码不起作用
  • 原文地址:https://www.cnblogs.com/zhaofei2013/p/2873063.html
Copyright © 2020-2023  润新知