zoukankan      html  css  js  c++  java
  • 检查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
  • 相关阅读:
    BZOJ 2038 小Z的袜子 莫队算法
    POJ 3407 球面距离
    POJ 1375 圆的切线
    BZOJ 1502 月下柠檬树 simpson积分
    UVA 11704
    POJ 1981 定长圆覆盖最多点
    HDU 3982 半平面交+圆和凸多边形面积并
    ZOJ 1104 二分
    使用Singleton来实现Flash和Flex的通信。
    校内API相关
  • 原文地址:https://www.cnblogs.com/zhaofei2013/p/2873063.html
Copyright © 2011-2022 走看看