java的tab事件_Incrontab(事件触发任务命令)文档说明

文档说明

该文档是介绍Linux中时间触发命令的使用,使用场景是当需要有触发事件执行命令的需求,比如如果某个文本被修改了,立即删除另外一个文本。

系统环境

操作系统:Linux version 3.10.0-229.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC) ) #1 SMP Fri Mar 6 11:36:42 UTC 2015

操作步骤

一般系统没有默认安装incrontab,所以需要自行下载安装。

1.下载incrontab rpm包

需要选择的incrontab rpm安装包版本号为:incron-0.5.9-2.el6.rf.x86_64.rpm

注:由于操作系统环境是centos7,故incron版本必须在0.5.9以上,否则无法运行

2.安装rpm包

安装rpm包将rpm包下载到指定文件夹里(本文指定目录为/soft/installation),并且安装rpm包

rpm -ivh incron-0.5.9-2.el6.rf.x86_64.rpm

70c107d49a0050adc31b65fabb90efab.png

注:其中rpm 所带参数-ivh代表安装rpm包并显示进度情况(--install--verbose--hash)

3.开启incrontab服务

/etc/init.d/incrond start

6f977eb821c7f2dc743271bc64e47950.png

4.添加触发任务

本例题中所添加的任务是,如果/soft/temp/test_incrontab.txt 文本中的文件被修改,即运行脚本/soft/bin/startupall.sh

首先需要配置incrontab任务表格

incrontab -e

注:e代表edit,修改配置

编辑incrontab表格,加入如下语句

/soft/temp/test_incrontab.txt  IN_MODIFY /soft/bin/startupall.sh

注:tomcat自带的/bin/startup.sh无法在incrontab中运行,原因是没有加上export JAVA_HOME=/soft/jdk8。

39d0409f7315559661cea2b62224e43b.png

: wq 保存

注:语句的格式是:    

具体的事件名见最后一页

5.显示incrontab表格确认任务

incrontab -l

ff954466f2b4aab9c951316701e389c0.png

6.查看日志

当修改test_incrontab.txt 内容后,可以查看日志,看看incrontab是否有监测到文件变化并执行。

tail -f /var/log/cron

8037240e8cd1d4d5102cd6107f980644.png

如图所示,表示脚本startupall.sh已执行。

附录:

事件名EventMeaning

Common Events

IN_ACCESSFile was accessed (read)

IN_ATTRIBMetadata was changed (permissions, timestamps, extended attributes, etc.)

IN_CLOSE_WRITEFile opened for writing was closed

IN_CLOSE_NOWRITEFile not opened for writing was closed

IN_CLOSECombinesIN_CLOSE_WRITEandIN_CLOSE_NOWRITE

IN_CREATEFile/directory created in watched directory

IN_DELETEFile/directory deleted from watched directory

IN_DELETE_SELFWatched file/directory was deleted

IN_MODIFYFile was modified

IN_MOVE_SELFWatched file/directory was moved

IN_MOVED_FROMFile moved out of watched directory

IN_MOVED_TOFile moved into watched directory

IN_MOVEA combination ofIN_MOVED_FROMandIN_MOVED_TO.

IN_OPENFile was opened

Special Events

IN_ALL_EVENTSCombines all of the above events

IN_DONT_FOLLOWDon't dereference pathname if it is a symbolic link

IN_ONESHOTMonitor pathname for only one event

IN_ONLYDIROnly watch pathname if it is a directory

Wildcard Event

IN_NO_LOOPDisable monitoring of events until the current event is handled completely (until its child process exits – avoids infinite loops)

------------------完------------------

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值