From b71fbd5224f132488189eab1477370c6e7f6cd49 Mon Sep 17 00:00:00 2001 From: Anonymous Date: Thu, 17 Jul 2025 11:11:42 -0400 Subject: [PATCH] The script tries to match lines with this regex in the read_logs function: ($user, $cpu, $memory, $command) = $l =~ m{^(\w+)\s+\d+\s+(\d{1,2}\.\d)\s+(\d{1,2}\.\d).*\d{1,2}:\d{2}\s+(.*)$}; Problems: (\w+) only matches word characters, but user:20 in ps pads usernames with spaces. The %CPU field could be >99, so (\d{1,2}\.\d) will not match '100' or higher. It expects a decimal like 2.3. The ps output for %CPU is integer (not decimal) for large values. The line starts with the process name, plus spaces. Fixed with: $l =~ s/^\s+//; # remove leading spaces my @fields = split /\s+/, $l, 11; my ($user, $pid, $cpu, $memory, $vsz, $rss, $tty, $stat, $start, $time, $command) = @fields; --- sys-snap.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sys-snap.pl b/sys-snap.pl index 9051c62..d5aed42 100755 --- a/sys-snap.pl +++ b/sys-snap.pl @@ -517,8 +517,9 @@ sub read_logs { } foreach my $l (@lines) { - my ( $user, $cpu, $memory, $command ); - ( $user, $cpu, $memory, $command ) = $l =~ m{^(\w+)\s+\d+\s+(\d{1,2}\.\d)\s+(\d{1,2}\.\d).*\d{1,2}:\d{2}\s+(.*)$}; + $l =~ s/^\s+//; + my @fields = split /\s+/, $l, 11; + my ($user, $pid, $cpu, $memory, $vsz, $rss, $tty, $stat, $start, $time, $command) = @fields; if ( defined $user && defined $cpu && defined $memory && defined $command ) {