reisinge has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks :-), I have two questions related to the following one-liner:
find /opt/splunk/syslog/ -iname "*log*" -type f -mtime +30 | perl -wne + 'BEGIN { $sum = 0 }; chomp; $sum += (stat)[7]; END { print "$sum\n" +}'
1) How should I quote it (escape the single quotes) when I want to execute it on a remote machine via SSH? Ex. ssh root@HOST 'ONE-LINER'
2) Is there is a (smart) way to incorporate the following subroutine into the one-liner?
sub scaleIt { my $size_in_bytes = shift; return unless defined $size_in_bytes; my ( $size, $n ) = ( $size_in_bytes, 0 ); ++$n and $size /= 1024 until $size < 1024; return sprintf "%.0f%s", $size, (qw[ B KB MB GB TB ])[$n]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: One-liner's quoting and subroutine
by Discipulus (Canon) on Sep 27, 2016 at 08:17 UTC | |
by reisinge (Hermit) on Sep 27, 2016 at 09:40 UTC | |
|
Re: One-liner's quoting and subroutine
by Happy-the-monk (Canon) on Sep 27, 2016 at 07:59 UTC | |
|
Re: One-liner's quoting and subroutine
by Anonymous Monk on Sep 27, 2016 at 07:35 UTC |