博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
检查Linux文件变更Shell脚本
阅读量:4659 次
发布时间:2019-06-09

本文共 1361 字,大约阅读时间需要 4 分钟。

领导让做个脚本,大概意思就是每天检查下系统中的几个常用的文件,检查是否做过变更,然后把日志发成邮件出来。

所以先写脚本了,脚本其实很简单,大概就是先把文件备份出来,然后下次运行的时候,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

 

 

 

转载于:https://www.cnblogs.com/zhaofei2013/archive/2013/01/23/2873063.html

你可能感兴趣的文章
研究Mysql优化得出一些建设性的方案
查看>>
POJ 2378 Tree Cutting (树的重心,微变形)
查看>>
SQL联查-转载
查看>>
Linux ssldump命令
查看>>
BZOJ4350: 括号序列再战猪猪侠【区间DP】
查看>>
silverlight Image Source URI : 一个反斜杠引发的血案
查看>>
《剑指offer》二叉树的深度
查看>>
【SQL Server 学习系列】-- 获取字符串中出现某字符的次数及字符某次出现的下标...
查看>>
树状数组2模板 Luogu 3368
查看>>
iOS App的状态
查看>>
C# 实现escape功能
查看>>
linux基础命令2(ls,cd)
查看>>
面向对象初识
查看>>
Word 2010中查找和替换功能高级技巧(转)
查看>>
优先队列
查看>>
堆内存破坏检测实战--附完整调试过程
查看>>
【knockoutjs】 Computed VS Pure Computed 区别
查看>>
JS向数组中添加/删除元素
查看>>
House Robber
查看>>
Best Time to Buy and Sell Stock II
查看>>