2011-11-01 42 views
1

這是我試圖分析日誌:不能使用字符串(「XXX」)爲標誌裁判而「嚴格裁判」使用

06:27:54 /data/noc/startup/startup_ptf_pats.sh startup initiated by waljoh @ Tue Nov 1  06:27:54 EDT 2011 
06:27:54 /data/noc/startup/startup_ptf_pats.sh verifying that engine is change controlled 
06:27:54 /data/noc/startup/check_change_controlled_files.sh all change controlled commands files are in synch 
06:27:54 /data/noc/startup/check_today_is_holiday.sh Today is NOT a holiday 
06:27:54 /data/noc/startup/check_ntpq.sh 159.79.35.42 time offset (0) is below 100 

這是我寫的劇本:

#!/usr/bin/perl 
use warnings; 
use strict; 

my $todays_date = `/bin/date +%m-%d-%y`; 
chomp $todays_date ; 

my $grabDIR = "/data/noc/startup/logs/"; 
my $grabFILE = "pats." . "$todays_date" . ".txt"; 

print "$grabDIR$grabFILE\n" ; 

my FILE; 
open (FILE, "more $grabDIR$grabFILE | "); 
while (<FILE>) { 
     my $line = $_; 
     print $line 
     sleep 1; 
} 

這是錯誤:

/data/noc/startup/logs/pats.11-01-11.txt Can't use string ("06:27:54 /data/noc/startup/start") as a symbol ref while "strict refs" in use at ./log_grap line 17, line 1.

+0

您在打印語句後缺少分號。 – Nick

回答

6

添加一個分號:

while (<FILE>) { 
    my $line = $_; 
    print $line; # semicolon! 
    sleep 1; 
} 
+0

有沒有更優雅的方式來獲取日期? – capser

+0

有沒有更好的方法來打開文件 - 我應該使用更多的管道 – capser

+3

請問這些作爲單獨的問題。 –