我有一堆日志文件,我想在它们更新时查看它们。我想出了下面的脚本:
#!/bin/bash
# Check if at least one log file is provided
if [ "$#" -eq 0 ]; then
echo "Usage: $0 /path/to/log/file1 [/path/to/log/file2 ...]"
exit 1
fi
if -p pipe_log
then
echo "Deleting existing pipe"
rm pipe_log
echo "Done!"
fi
mkfifo pipe_log
echo "Setting up log publishing"
# Start tail on each log file and pipe to nc in the background
for log_file in "$@"; do
(tail -n 0 -F "$log_file" >> pipe_log) &
done
echo "Done!"
echo "Starting server"
(nc -lk -p 12345 -s 0.0.0.0 < pipe_log )
echo "Finished"
# Wait for all background processes to finish
wait
rm pipe_log
tail
我通过将每个文件的日志写入命名管道来合并日志。然后,我使用 发布综合日志nc -lk < pipe_log
。但如果我尝试读取日志,则nc localhost 12345
没有输出。
我可以直接从 FIFO 读取,因此从管道重定向到我无法确定的cat pip_log
问题肯定存在。nc
注意:该问题之前发布于所以但没有收到回复。