博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
阿铭每日一题 day 7 20180117
阅读量:7020 次
发布时间:2019-06-28

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

 

方法一:

1 #!/bin/bash2 while true3 do4 find /data/web/attachment/ -type f -mmin -5 -exec echo $(date +%Y/%m/%d\ %H:%M:%S) {} \; >> /tmp/day7.log5 sleep 56 done

 

 

 

day7=参考答案=~ps.不是唯一答案哦
解析
1、不要想的太复杂,核心命令只有一个:find /data/web/attachment/ -type f - mmin -5
2、每5分钟检测一次,需要有一个计划任务,每隔5分钟执行一次。脚本检测的时候,使用find命令查找5分钟内有过更新的文件,若是有更新,那这个命令会输出东西,否则是没有输出的。固,可以把输出结果的行数作为比较对象,看看它是否大于0。
3、当然大家还可以用find命令执行后,看$?的返回值是否是0。
 
【参考答案】

1 #!/bin/bash 2  3 d=`date -d " -5 min" +%Y\%m\%d\%H\%M` 4 basedir="/data/web/attachment" 5  6 find $basedir -type f -mmin -5 > /tmp/newf.txt 7 n=`wc -l /tmp/newf.txt|awk '{print $1}'` 8 if [ $n -gt 0 ] 9 then10   /usr/bin/mv /tmp/newf.txt /tmp/$d11 fi

 

 

 

crond计划任务

1 */5 * * * * /bin/bash /root/scripts/day7_20180117.sh

 

转载于:https://www.cnblogs.com/ivan-yang/p/8323563.html

你可能感兴趣的文章
坐标系与基本图元(5)
查看>>
IE8崩溃在CElement::GetUpdatedLayoutWithContext
查看>>
用PHP实现单向链表
查看>>
PIL中分离通道发生“AttributeError: 'NoneType' object has no attribute 'bands'”
查看>>
通过rails console执行sql语句
查看>>
调试+运行
查看>>
you-get下载视频
查看>>
centos 安装pecl
查看>>
[golang] Glide 包管理
查看>>
教程:VS2010 之TFS入门指南(转载)
查看>>
微信小程序
查看>>
spark 调优参数
查看>>
android中xml tools属性详解
查看>>
Volley全方位解析,带你从源码的角度彻底理解
查看>>
php优秀网摘
查看>>
GDI+ 双缓冲
查看>>
git https连接方式,记住密码
查看>>
编译安装与gcc编译器
查看>>
初始化参数(Initialization Parameter)知识合集 based on 11g
查看>>
opencv中 Mat矩阵申明形式
查看>>