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上传约定格式的文件到服务器指定目录下,应用程序能实时监控该目录下文件变化,如果上传的文件格式符合要求,将将按照每一行读取解析再写入到数据库,解析完之后再将文件改名. 一. 一开 ...
随机推荐
- button 获取 cell
- (void)cellBtnClicked:(id)sender event:(id)event { NSSet *touches =[event allTouches]; ...
- Eclipse 修改编码方式
1.修改全局(Eclipse默认)文本编码方式 2.修改某个工程编码方式 右键工程点击”属性“后,如下图
- react native的Navigator组件示例
import React, {Component} from 'react';import {ScrollView, StyleSheet, Text, View, PixelRatio} from ...
- C - Catch That Cow POJ - 3278
//标准bfs #include <iostream> #include <cstdio> #include <algorithm> #include <cm ...
- 用python编写一个计算器
# 1 - 2 * ((60-30 +(-40.0/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2)))# 通过Pyt ...
- springMVC-接收数据-参数绑定
接收数据-参数绑定 #Method Arguments概观 Same in Spring WebFlux The table below shows supported controller meth ...
- JDBC事务之理论篇
事务: 事务是数据库操作的基本逻辑单位,一般来说,事务总是并发地执行,并且这些事务可能并发地存取相同的数据.因此为了保证数据的完整性和一致性,所有的JDBC相符的驱动程序都必须支持事务管理. 事务可以 ...
- corn表达式 经典
https://www.cnblogs.com/GarfieldTom/p/3746290.html
- ruby字符串处理
1. str="abc123"puts str[0].chr => a puts str[0] =>a的ascii码 2.中文字符串的正则 ...
- asp。Net 页面传值
00.引言 Web页面是无状态的, 服务器对每一次请求都认为来自不同用户,因此,变量的状态在连续对同一页面的多次请求之间或在页面跳转时不会被保留.在用ASP.NET 设计开发一个Web系统时, 遇到一 ...