简体   繁体   English

bash:无限期地使用并行命令继续运行脚本

[英]bash: keep running script with parallel command indefinitely

I have logging system that creates new log file every second in Ubuntu Server.我有日志系统,它每秒在 Ubuntu 服务器中创建一个新的日志文件。 I have developed script called "processor.sh" that runs every second to extract important information from the newly created log files.我开发了名为“processor.sh”的脚本,该脚本每秒运行一次,以从新创建的日志文件中提取重要信息。 Previously, I used to use watch command to run the processors.sh indefinitely:以前,我曾经使用 watch 命令无限期地运行 processor.sh:

watch -n1 ./processor.sh 

Now I started to use parallel command like the following:现在我开始使用像下面这样的并行命令:

ls *.log | parallel xargs ./processors.sh

I believe using watch to run it continuously is a wrong thing.我相信使用 watch 连续运行它是错误的。 How can I keep running processor.sh forever every second with parallel command?如何使用并行命令每秒永远运行processor.sh?

Here is one way:这是一种方法:

while true; do
  parallel ./processors.sh ::: *.log
  sleep 1
done

But I think this will be way better:但我认为这会更好:

inotifywait -qmre MOVED_TO -e CLOSE_WRITE --format %w%f `pwd` |
  parallel ./processors.sh

This will start the processing when another process stops writing to a .log-file and closes it.这将在另一个进程停止写入 .log 文件并关闭它时开始处理。

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

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