不用守护进程怎么样读取定时更新的log文件
时间:2011-07-24
来源:互联网
最近在做perl日志解析的东西,之前写了一个守护进程
#/usr/bin/per
my $pid = fork()
if($pid)
{
}
setpgrp
while(1)
{
sleep(6);
open(FILE,"2010.log");
seek(FILE,$currentpos,0);
while($line=<FILE>)
{
$currentpos=tell;
print "--$line--\n";
}
}l
这样每次只读取更新的日志文件,不需要重新读,但是现在不要用守护进程,要把代码放到crontab下,就是每隔一段时间会定时的去读文件
#/usr/bin/per
open(FILE,"2010.log");
seek(FILE,$currentpos,0);
while($line=<FILE>)
{
$currentpos=tell;
print "--$line--\n";
}
或者
#/usr/bin/per
open(FILE,"2010.log");
while($line=<FILE>)
{
print "$line if$.>=n";
}
这样每次重新运行文件的时候$currentpos都会归零,也就是说要重头读,有没有那种能保存起来的环境变量,每次运行文件的时候会从上一个值读取
#/usr/bin/per
my $pid = fork()
if($pid)
{
}
setpgrp
while(1)
{
sleep(6);
open(FILE,"2010.log");
seek(FILE,$currentpos,0);
while($line=<FILE>)
{
$currentpos=tell;
print "--$line--\n";
}
}l
这样每次只读取更新的日志文件,不需要重新读,但是现在不要用守护进程,要把代码放到crontab下,就是每隔一段时间会定时的去读文件
#/usr/bin/per
open(FILE,"2010.log");
seek(FILE,$currentpos,0);
while($line=<FILE>)
{
$currentpos=tell;
print "--$line--\n";
}
或者
#/usr/bin/per
open(FILE,"2010.log");
while($line=<FILE>)
{
print "$line if$.>=n";
}
这样每次重新运行文件的时候$currentpos都会归零,也就是说要重头读,有没有那种能保存起来的环境变量,每次运行文件的时候会从上一个值读取
作者: 010shiwei010 发布时间: 2011-07-24
dbmopen (my %position, "position", 0666);
$position{'currentpos"} = $currentpos;
dbmclose %position;
$position{'currentpos"} = $currentpos;
dbmclose %position;
作者: Kitaisky 发布时间: 2011-07-24
我运行了,怎么还是重头开始的,不能只读更新的文件
#/usr/bin/per
open(FILE,"2010.log");
dbmopen (my %position, "position", 0666);
seek(FILE,$currentpos,0);
while($line=<FILE>)
{
$currentpos=tell;
$position{'currentpos"} = $currentpos;
print "--$line--\n";
}
dbmclose %position;
是这样吗
#/usr/bin/per
open(FILE,"2010.log");
dbmopen (my %position, "position", 0666);
seek(FILE,$currentpos,0);
while($line=<FILE>)
{
$currentpos=tell;
$position{'currentpos"} = $currentpos;
print "--$line--\n";
}
dbmclose %position;
是这样吗
作者: 010shiwei010 发布时间: 2011-07-24
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28