有没有办法让tail -F发出哔哔声?

Ali*_*Ali 24 less tail bell

当新数据进来时(在文件中添加一个新行),有没有办法发出tail -Fless发出哔哔声(在终端中响铃)。或者是否有任何其他 unix 实用程序可以在 linux 或 mac 上执行此操作。

Nil*_*ils 14

一个想法可能是通过管道输出tailthroughsed并用 bell/newline 替换换行符。

但是,如果您tailx-window 中使用,则可能有一个更简单的解决方案。当窗口的内容发生变化(闪烁、铃声等)时,您可以在那里执行一个操作。

  • 不要替换换行符,将其添加到行尾。 (5认同)
  • @Ali 确实, sed 逐行执行,您不会直接看到换行符。`sed -e $'s/$/\a/'` 在每行末尾添加一个 `$'\a'`(ksh/bash/zsh 语法中的钟形字符)。 (5认同)

Tim*_*edy 13

如果您使用 GNU screen,您可以将其设置为“观察”带有尾部的窗口,它会在您的状态栏中或通过您的 termcap 定义的铃声提醒您,该窗口中有新的输出。

http://www.gnu.org/software/screen/manual/html%5Fnode/Monitor.html#Monitor


编辑:只需要添加这个,因为你提到了 mac os x

只是为了好玩,如果您正在寻找特别的东西,您可以使用 Mac OS X 的say命令来读取您正在观看的文件。只需logtail从以下位置获取命令:

http://www.hmug.org/pub/MacOS_X/BSD/Administration/Log/logcheck/

并在如下脚本中使用它:

#!/bin/bash

file=$1
offset=$(basename "$1")

# while true... let this thing run until it's killed...
while true; do
    output=$(/usr/local/bin/logtail $file .${offset}.offset)
    if [ ! -z "$output" ]; then

        # print the output and say ding
        echo "$output" && say ding
        # to have the file read aloud to you, uncomment the following:
        say "$output"

        fi
    # recheck every 5 seconds
    sleep 5
done
Run Code Online (Sandbox Code Playgroud)


and*_*coz 10

您可以使用multitail。它是一个增强的尾部,支持在正则表达式匹配上执行命令。

例如,每次记录martian数据包时,以下命令都会播放声音并打开 xmessage 窗口。

multitail -ex "martian source" "play beep.wav; xmessage " -i /var/log/messages
Run Code Online (Sandbox Code Playgroud)


Ali*_*Ali 5

只是为了记录,正如@Nils 建议的那样,我正在使用向每一行sed添加一个bell

sed由@Gilles提供线

sed -e $'s/$/\a/' 
Run Code Online (Sandbox Code Playgroud)

在我的 mac 上工作(我在我的终端\首选项\高级中启用了“可听铃”和“可视铃”)。