From: Dobrica Pavlinusic Date: Sun, 16 Jul 2023 07:54:20 +0000 (+0200) Subject: remove all output without DEBUG=1 for cron use X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;h=82af3b5eb48d209d6f30c497741ba206d47e9f49;p=eg5120 remove all output without DEBUG=1 for cron use --- diff --git a/parse-node-logs.pl b/parse-node-logs.pl index 7e0d4ad..5b973fd 100755 --- a/parse-node-logs.pl +++ b/parse-node-logs.pl @@ -10,20 +10,23 @@ use autodie; my $path = '/home/nodelogs/c405f97667784094bca5cfa52af0bcf1/'; +my $last_files = $ENV{LAST} || 3; # process last 3 logs by mtime + +my $debug = $ENV{DEBUG} || 0; + # select _id,json->'received',time,to_timestamp((json->>'received')::int8/1000) - interval '1 hour' from nodelog ; my $dbh = DBI->connect("dbi:Pg:dbname=eg5120", "dpavlin", "", { RaiseError => 1 }); -warn "# truncate table nodelog"; +warn "# truncate table nodelog" if $debug; $dbh->do( qq{ truncate table nodelog } ); # FIXME my $sth = $dbh->prepare(qq{insert into nodelog (time,json) values (?,?)}); -my $last_files = $ENV{LAST} || 3; # process last 3 logs by mtime foreach my $filename ( sort { -M $a <=> -M $b } (glob("$path/node-red-out*.log")), ) { last if $last_files-- == 0; - warn "# $filename"; + warn "# $filename" if $debug; open(my $log, '<', $filename); my $in_json = 0; my $json; @@ -50,7 +53,7 @@ foreach my $filename ( if ( $_ eq '}' ) { $in_json = 0; #warn "- in_json"; - warn ">>> $time [[[[ $json ]]]]"; + warn ">>> $time [[[[ $json ]]]]" if $debug; write_file '/dev/shm/json', $json; $sth->execute( $time, $json ); $json = '';