[英]simulating tail -f in Perl
按照perldoc中提供的解决方案 ,我正在尝试模拟tail -f
但是它没有按预期工作。 下面的代码可以第一次打印所有行,但不能打印新添加的行。 如果我在这里遗漏任何东西,请您详细说明。
#!/usr/bin/perl
open (LOGFILE, "aa") or die "could not open file reason $! \n";
for (;;)
{
seek(LOGFILE,0,1); ### clear OF condition
for ($curpos = tell(LOGFILE); <LOGFILE>; $curpos = tell(LOGFILE))
{
print "$_ \n";
}
sleep 1;
seek(LOGFILE,$curpos,0); ### Setting cursor at the EOF
}
对我来说很好。 您如何更新"aa"
? 如果它是对"aa"
的buffered
写入,则不会立即看到数据。 您可以在其他终端中尝试以下操作并检查是否看到任何更新。
while ( 1 )
echo "test" >> aa
end
如果您正在使用perl更新aa
,请查看本节有关缓冲以及如何禁用的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.