当新数据进来时(在文件中添加一个新行),有没有办法发出tail -F
或less
发出哔哔声(在终端中响铃)。或者是否有任何其他 unix 实用程序可以在 linux 或 mac 上执行此操作。
Nil*_*ils 14
一个想法可能是通过管道输出tail
throughsed
并用 bell/newline 替换换行符。
但是,如果您tail
在x-window 中使用,则可能有一个更简单的解决方案。当窗口的内容发生变化(闪烁、铃声等)时,您可以在那里执行一个操作。
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)
只是为了记录,正如@Nils 建议的那样,我正在使用向每一行sed
添加一个bell
。
在sed
由@Gilles提供线
sed -e $'s/$/\a/'
Run Code Online (Sandbox Code Playgroud)
在我的 mac 上工作(我在我的终端\首选项\高级中启用了“可听铃”和“可视铃”)。