我有一个AWS EC2实例,想要安装inotify-tools.我通过执行命令添加了存储库:rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm然后执行yum install inotify-tools但得到没有包inotify工具可用.
请帮忙
要监视linux中的文件,我可以使用这样的inotify-tools
#!/bin/bash
# with inotify-tools installed, watch for modification of file passed as first param
while inotifywait -e modify $1; do
# do something here
done
Run Code Online (Sandbox Code Playgroud)
但是我如何在OSX中实现这一目标?
我有一个与我一起观看的Sphinx文档的文件夹inotifywait(来自inotify-tools).该脚本重新构建html&singlehtml并刷新Chrome.
#!/bin/sh
inotifywait -mr source --exclude _build -e close_write -e create -e delete -e move | while read file event; do
make html singlehtml
xdotool search --name Chromium key --window %@ F5
done
Run Code Online (Sandbox Code Playgroud)
保存单个文件时,此工作正常.但是,当我hg update使用旧版本或粘贴文件source夹中的多个文件时,它会为每个文件触发脚本.
是否有一个简单的解决方法(没有编写自定义python脚本 - 我可以这样做)让它在启动脚本之前等待几分之一秒?
我特意试图在2个子目录中同时观察2种不同的文件类型:
'css'子目录中 'js'子目录.styl文件类型中的.coffee文件类型
我只知道这么多bash而且我正试图让这样的东西发挥作用
while inotifywait --format %w%f ./{css,js}/*.{styl,coffee}; do
# regex pattern to match the file ending
# and define it to $ending
if[ $ending == coffee ]
then
coffee -c $file
elif[ $ending == styl ]
then
stylus -c $file
fi
done
Run Code Online (Sandbox Code Playgroud)
//编辑//修改此行:
while inotifywait --format %w%f ./{css,js}/*.{styl,coffee}; do
Run Code Online (Sandbox Code Playgroud)
所以现在它检查两个文件,但是如果css文件夹上没有.coffee文件,或者js中没有.styl文件,则会返回错误,表明没有找到文件.
另外我注意到当我运行这个脚本时,它返回/运行以下3次
Setting up watches.
Watches established.
./css/styles.styl
Run Code Online (Sandbox Code Playgroud) 我使用inotify-tools和unison在机器之间同步文件夹.因为我有一个要同步的大文件夹,所以我只需编写一个inotifywait脚本来自动完成工作.让inotifywait监控大文件夹的子目录以获得更好的性能是否明智?
我有一个bash脚本,它使用inotify-tools处理一些数据,以了解文件系统上何时发生了某些事件.如果在bash控制台中运行它可以正常工作,但是当我尝试将其作为守护程序运行时它会失败.我认为原因是inotifywait命令调用的所有输出都转到了一个文件,因此,之后的部分| while不再被调用.我该如何解决这个问题?这是我的剧本.
#!/bin/bash
inotifywait -d -r \
-o /dev/null \
-e close_write \
--exclude "^[\.+]|cgi-bin|recycle_bin" \
--format "%w:%&e:%f" \
$1|
while IFS=':' read directory event file
do
#doing my thing
done
Run Code Online (Sandbox Code Playgroud)
因此,-d告诉inotifywait要作为守护进程运行,-r以递归方式执行,并且-o是保存输出的文件.在我的情况下,文件是/dev/null因为我不需要输出,除了在命令(| while...)后处理部分