我在编辑 LaTeX 文件时使用llpp pdf 查看器。为了让它在编译时自动刷新 pdf 文件,我使用包装器来启动它(参见this)。
处理等待和刷新的部分是这个:
inotifywait -m -e close_write $1 | while read; do
kill -HUP $pid_llpp
done &
Run Code Online (Sandbox Code Playgroud)
我的问题如下:每当编译 tex 文件时发生错误,就不会产生 pdf 输出并且 llpp 正在关闭。我尝试过类似的事情:
inotifywait -m -e close_write $1 | while read; do
if [ -a $1 ]
then
kill -HUP $pid_llpp
fi
done &
Run Code Online (Sandbox Code Playgroud)
它部分工作:当编译期间发生错误时,llpp 不会关闭但不再刷新...
有人能帮我解决这个问题吗?
我想使用 inotifyway 来监视文件夹中新创建或移动的文件,但仅限于文件。
假设我的文件夹名为“watched_folder_test”,我的文件名为“toto.txt”。如果我使用 mv 命令将文件移动到 watched_folder_test 我得到通知我想要
假设在 watched_folder_test 中,我有一个名为 foo 的文件夹,我创建了一个名为“bar.txt”的文件。我收到了我想要的通知。
但这是我的问题。如果我在 watch_folder_test 之外有一个文件夹名称 foo 并且我在其中有一个文件名 bar.txt ( foo/bar.txt ) 并且我将整个文件夹移动到 watch_folder_test 中。我只收到 foo 已创建的通知!没有关于 bar.txt 的内容。但是,我并不真正关心 foo,我只想知道“bar.txt”
到目前为止,这是我的代码
#!/bin/bash
inotifywait -mr /home/romain/depot/watched_folder_test -e create -e moved_to |
while read path action file; do
echo "The file '$file' appeared in directory '$path' via '$action'"
for ac in $action
do
isdir=`echo $ac | grep 'ISDIR'`
if [ $? == 0 ]
then
echo "It's a folder"
else
echo "It's …Run Code Online (Sandbox Code Playgroud) 我写了一个bash脚本来监控一个特定的目录“/root/secondfolder/”,脚本如下:
#!/bin/sh
while inotifywait -mr -e close_write "/root/secondfolder/"
do
echo "close_write"
done
Run Code Online (Sandbox Code Playgroud)
当我在“/root/secondfolder/”中创建一个名为“fourth.txt”的文件并向其中写入内容,保存并关闭它时,它输出以下内容但不回显“close_write”:
/root/secondfolder/ CLOSE_WRITE,CLOSE fourth.txt
Run Code Online (Sandbox Code Playgroud)
有人可以指出我正确的方向吗?
我正在学习使用 inotifywait,特别是通过使用以下脚本:https ://unix.stackexchange.com/questions/24952/script-to-monitor-folder-for-new-files 。我不明白的是为什么我的脚本在我使用pid x.
36285 pts/1 S+ 0:00 /bin/bash ./observe2.sh /home/user1/testfolder
36286 pts/1 S+ 0:00 inotifywait -m /home/user1/testfolder -e create -e moved_to
36287 pts/1 S+ 0:00 /bin/bash ./observe2.sh /home/user1/testfolder
Run Code Online (Sandbox Code Playgroud)
为了更快地测试,我更改了链接脚本,以便您可以通过 $1 传递任何文件夹进行观察,并保存为observe2.sh:
#!/bin/bash
inotifywait -m $1 -e create -e moved_to |
while read path action file; do
echo "The file '$file' appeared in directory '$path' via '$action'"
# do something with the file
done
Run Code Online (Sandbox Code Playgroud)
为什么脚本进程会出现两次?过程中是否有分叉?有人可以解释为什么会发生两个进程的这种行为吗?
inotifywait ×4
bash ×3
linux ×2
monitoring ×2
echo ×1
inotify ×1
latex ×1
pdf ×1
ubuntu ×1
unix ×1