shell脚本,如何监控目录下的文件内容是否被修改。
第一种方法是通过cmp来进行比对
[root@localhost bo]# ls
.html .html .html .html .html .html .html .html .html cat.sh
[root@localhost bo]# cat cat.sh
#!/bin/bash [ ! -f /root/wyb/bo/cat.log ] && cat *.html > /root/wyb/bo/cat.log
cat *.html >tmp.log cmp tmp.log /root/wyb/bo/cat.log [ $? -eq ] && echo yes || echo no
[root@localhost bo]# bash cat.sh
yes
[root@localhost bo]# vi .html
[root@localhost bo]# bash cat.
cat.log cat.sh
[root@localhost bo]# bash cat.sh
tmp.log /root/wyb/bo/cat.log differ: byte , line
no
[root@localhost bo]#
第二种方法是通过md5来检验
[root@localhost bo]# ls
.html .html .html .html .html .html .html .html .html cat.log cat.sh md5.sh tmp.log
[root@localhost bo]# cat md5.sh
#!/bin/bash
LANG=en dosomething()
{
a=`grep 'FAILED' /tmp/md5.check|awk -F':' '{print $1}'`
echo -e "\033[32m$a\033[0m changed !"
} find_file(){ b=`find /root/wyb/bo -type f|xargs md5sum > /tmp/html.md5`
echo $b } success()
{
echo "not change"
} [ ! -f /tmp/html.md5 ] && find_file
md5sum -c /tmp/html.md5 > /tmp/md5.check >&
[ $? -eq ] && success || dosomething [root@localhost bo]# bash md5.sh not change
[root@localhost bo]# echo >> .html
[root@localhost bo]# bash md5.sh
/root/wyb/bo/.html changed !
[root@localhost bo]#
shell脚本,如何监控目录下的文件内容是否被修改。的更多相关文章
- shell脚本仅列出当前目录下的文件及文件夹
#!/bin/bash function ergodic(){ ` # do # "/"$file ] # then # ergodic $"/"$file # ...
- shell脚本 批量转换目录下文件编码
发布:JB01 来源:脚本学堂 [大 中 小] 分享一例shell脚本,实现可以批量转换目录下的文件编码,很实用的一个小shell,有需要的朋友参考下.原文地址:http://www.jb ...
- 一个用shell写的统计目录下统计文件行数的代码
此代码是用来回忆当初学的shell脚本,很多知识忘了,写这个花了我三个小时的时间 #!/bin/ksh #count *.c file the num of lineg_csum=0g_hsum=0 ...
- linux查看目录下所有文件内容中是否包含某个字符串
转发自:http://blog.csdn.net/yimingsilence/article/details/76071949 查找目录下的所有文件中是否含有某个字符串 find .|xargs gr ...
- linux 查找目录下的文件内容并替换(批量)
2.sed和grep配合 命令:sed -i s/yyyy/xxxx/g `grep yyyy -rl --include="*.txt" ./` 作用:将当前目录(包括子目录)中 ...
- AssetsUtils【读取assets、res/raw、./data/data/包名/目录下的文件】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 封装了以下功能: 1.读取assets目录下的资源html.文件.图片,将文件复制到SD卡目录中: 2.读取res/raw目录下的文 ...
- .net core 读取本地指定目录下的文件
项目需求 asp.net core 读取log目录下的.log文件,.log文件的内容如下: xxx.log ------------------------------------------beg ...
- shell脚本监控目录下文件被篡改时报警
思路: 目录下文件被篡改的几种可能: 1.被修改 2.被删除 3.新增文件 md5命令详解 参数: -b 以二进制模式读入文件内容 -t 以文本模式读入文件内容 -c 根据已生成的md5值,对现存文件 ...
- java利用WatchService实时监控某个目录下的文件变化并按行解析(注:附源代码)
首先说下需求:通过ftp上传约定格式的文件到服务器指定目录下,应用程序能实时监控该目录下文件变化,如果上传的文件格式符合要求,将将按照每一行读取解析再写入到数据库,解析完之后再将文件改名. 一. 一开 ...
随机推荐
- Ogre 学习记录
http://www.cppblog.com/richardhe/articles/55722.html 1: 设计初衷 它设计初衷是完全跨平台的.抽象的接口隐藏了平台相关的细节. 它设计初衷是大幅度 ...
- Mol Cell Proteomics. |陈洁| 整合鸟枪法蛋白质组学中鉴定和定量的错误率
大家好,本周分享的是发表在MCP上的一篇关于鸟枪蛋白质组学中的错误率的文章,题目是Integrated identification and quantification error probabil ...
- iOS 8 录音重放出现 OSStatus error 1685348671 / 2003334207 问题的解决办法
许多录音类 APP 都提供录音回放功能,大家在做这类 APP 的时候也经常会遇到这个需求.当大家用以前的套路在 iOS 8 上录音的时候,在模拟器上跑得挺好的,但是一上真机就跪了,为什么?因为真机底层 ...
- sql数据库查询结果字段包含换行符导致复制到Excel发生错位问题的解决
问题描述:在工作过程中,有时会遇到这样的问题,写好sql查询语句在数据库中查询数据,看到行数(比如说是1000行),但是把查询结果复制到Excel里面,却发生了行列错位问题,而导致Excel里面的行数 ...
- PHP不重新编译,单独添加模块扩展的方法
php自身提供了很多扩展,比如curl,gmp, mbstring等.我们在编译安装php时未必安装了所有扩展.那么在安装完php后,如果想单独安装某个php自身的扩展怎么办呢? 我们以curl扩展模 ...
- WKWebView简单使用
#import <WebKit/WebKit.h> @interface SchoolOverviewsViewController ()<WKUIDelegate,WKNaviga ...
- C# 可空类型(Nullable)
C# 提供了一个特殊的数据类型,nullable 类型(可空类型),可空类型可以表示其基础值类型正常范围内的值,再加上一个 null 值. 例如,Nullable< Int32 >,读作& ...
- 抛出异常-throws和throw
package com.mpp.test; import java.util.Scanner; public class TryDemoFour { public static void main(S ...
- Codeforces Round #547 (Div. 3) B.Maximal Continuous Rest
链接:https://codeforces.com/contest/1141/problem/B 题意: 给n个数,0代表工作,1代表休息,求能连续最大的休息长度. 可以连接首尾. 思路: 求普通连续 ...
- 2016级萌新选拔赛BE题
#include<bits/stdc++.h> using namespace std; #define ll long long ll a[]; ll d[]; int main() { ...