kris1511 has asked for the wisdom of the Perl Monks concerning the following question:
#Write a script which parses /var/log/messages and generates a CSV wit +h two columns: minute, number_of_messages in sorted time order. #---------- begin sample output ---------- #minute, number_of_messages #Jan 20 03:25,2 #Jan 20 03:26,2 #Jan 20 03:30,2 #Jan 20 05:03,1 #Jan 20 05:20,1 #Jan 20 05:22,6 #---------- end sample output ------------"""
Associated Text file is as follows
Jan 20 03:25:08 fakehost logrotate: ALERT exited abnormally with [1] Jan 20 03:25:09 fakehost run-parts(/etc/cron.daily)[20447]: finished l +ogrotate Jan 20 03:26:21 fakehost anacron[28969]: Job 'cron.daily' terminated Jan 20 03:26:22 fakehost anacron[28969]: Normal exit (1 job run) Jan 20 03:30:01 fakehost CROND[31462]: (root) CMD (/usr/lib64/sa/sa1 1 + 1) Jan 20 03:30:01 fakehost CROND[31461]: (root) CMD (/var/system/bin/sys +-cmd -F > /dev/null 2>&1) Jan 20 05:03:03 fakehost ntpd[3705]: synchronized to time.faux.biz, st +ratum 2 Jan 20 05:20:01 fakehost rsyslogd: [origin software="rsyslogd" swVersi +on="5.8.10" x-pid="20438" x-info="http://www.rsyslog.com"] start Jan 20 05:22:04 fakehost cs3[31163]: Q: ".../bin/rsync -LD ": symlink + has no referent: "/var/syscmds/fakehost/runit_scripts/etc/runit/serv +ice/superImportantService/run"#012Q: ".../bin/rsync -LD ": rsync erro +r: some files/attrs were not transferred (see previous errors) (code +23) at main.c(1039) [sender=3.0.6] Jan 20 05:22:04 fakehost cs3[31163]: I: Last 2 quoted lines were gene +rated by "/usr/local/bin/rsync -LD --recursive --delete --password-fi +le=/var/syscmds/modules/rsync_password /var/syscmds/fakehost syscmds@ +fakehost::syscmds_rsync" Jan 20 05:22:08 fakehost cs3[31163]: Q: ".../sbin/sv restart": ok: ru +n: /export/service/cool-service: (pid 32323) 0s Jan 20 05:22:08 fakehost cs3[31163]: I: Last 1 quoted lines were gene +rated by "/sbin/sv restart /export/service/cool-service" Jan 20 05:22:09 fakehost cs3[31163]: R: cs3: The cool service on fak +ehost does not appear to be communicating with the cool service leade +r. Automating a restart of the cool service in attempt to resolve th +e communication problem. Jan 20 05:22:37 fakehost ACCT_ADD: WARNING: Manifest /var/syscmds/inpu +ts/config-general/doit.txt has been processed already, bailing
I am getting error Can't call method print on undefine value on following line : $csv->print ( OUT, $_ ) for sort keys %hash; # Error's Out Any idea. Thanks in Advance!!!open(IN, "fixed.txt") or die "cannot open file $!"; my %hash ={}; my @arr; while(my $row =<IN>){ push @arr, unpack("x0 A12",$row ); #print unpack("x0 A12",$row ),"\n"; } $hash{$_}++ for @arr; # Adding Header my @heading = ("minute", "number of messages"); open (OUT, '>:encoding(UTF-8)', "outputfile.csv") or die $!; $csv->print ( OUT, $_ ) for @heading; $csv->print ( OUT, $_ ) for sort keys %hash; # Error's Out close OUT;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Logfile Summarize messages by time and export to CSV
by huck (Prior) on Aug 31, 2017 at 22:56 UTC | |
|
Re: Logfile Summarize messages by time and export to CSV
by Tux (Canon) on Sep 01, 2017 at 06:20 UTC |