我想运行一个脚本,将文件的更改传输到另一个文件(如日志文件),并在终端中打印出来。
我更喜欢使用inotify工具,但也欢迎其他建议:)
我尝试使用带有-m前缀的inotifywait,但之后的命令不会运行,因为inotifywait-m会不断重复自身。
使用不带前缀的inotifywait也没有帮助。

...
inotifywait -m $file >> logfile.log
...

最佳答案

您可以尝试使用tee过滤器,它将从inotfywait读取输入并同时输出到终端和文件。

inotifywait -m file | tee -a logfile.log

要在后台运行此命令,请参见下面的内容,但在运行此命令时,您将获得到终端的inotifywait输出。
nohup inotifywait -m file | tee -a logfile.log &

08-26 01:39