简体   繁体   English

让incron inotify工作的麻烦

[英]trouble getting incron inotify to work

so after alex answer here are my steps : 亚历克斯回答这里是我的步骤:

creating shell code 创建shell代码

root@ip[/]# touch mylog.sh
root@ip[/]# nano mylog.sh

copying the code in the mylog.sh 复制mylog.sh中的代码

#!/bin/bash
echo "File $1 created." >> /mylog.log

permission 允许

root@ip[/]# chmod +x mylog.sh

creating the log file 创建日志文件

root@ip[/]# touch mylog.log 

opening icron table 打开icron表

incrontab -e

putting new command in 把新命令放入

/test/ IN_CREATE mylog.sh $@$#

reloading incron - creating a new file - checking the log file 重新加载incron - 创建一个新文件 - 检查日志文件

root@ip[/]# incrontab --reload
requesting table reload for user 'root'...
request done

root@ip[/]# cd test
root@ip[/test]# touch newfile.txt

root@ip[/test]# cd /
root@ip[/]# nano mylog.log

but still empty log file ... am i missing something ? 但仍然是空的日志文件...我错过了什么?


finally calling shell script with full path did the trick so : 最后用完整路径调用shell脚本就可以了:

/test/ IN_CREATE /mylog.sh $@$#

You can usually find the incron logs in /var/log/messages 您通常可以在/ var / log / messages中找到incron日志

If you want to log events to a specific file you can use: 如果要将事件记录到特定文件,可以使用:

/test/ IN_CREATE mylog.sh $@$#

where mylog.sh is a shell script which handles the logging. 其中mylog.sh是一个处理日志记录的shell脚本。

#!/bin/bash
echo "File $1 created." >> /home/myuser/filescreated.log

Don't forget to give execution permission to this shell script by chmod +x mylog.sh 不要忘记通过chmod + x mylog.sh为此shell脚本授予执行权限

Explanation: As soon as you start using parameters for your command which you're calling, you have to put it all into a shell script. 说明:一旦开始使用您正在调用的命令的参数,就必须将其全部放入shell脚本中。 Since incron don't pass the arguments to your command but interprets it as an argument for itself. 因为incron不会将参数传递给您的命令,而是将其解释为自身的参数。

Don't forget to call incrontab --reload after changing the incrontab. 不要忘记在更改incrontab后调用incrontab --reload。

Another example 另一个例子

incrontab -e incrontab -e

/text/ IN_CREATE /home/myuser/mylog.sh $@ $#

mylog.sh mylog.sh

#!/bin/bash
echo "$(date) File $2 in $1 created." >> /home/myuser/log.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM