Created
November 24, 2022 18:07
-
-
Save yaasita/cc962c52a98b250aa67bf3952bd84b40 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use feature qw(:5.10); | |
use utf8; | |
# ipはダミー | |
my $WEBARENA_IPV4 = "203.0.113.1"; | |
my $RESULT_FILE = "./out/rsync.csv"; | |
my @result; | |
sub rsync { | |
my $host = shift; | |
my $cmd; | |
my $output = `rsync -v -W --skip-compress=dat root\@$WEBARENA_IPV4:rand.dat /tmp/`; | |
say $output; | |
my $result = { | |
time => time(), | |
host => $host | |
}; | |
if ($output =~ /([\d,\.]+) bytes\/sec/) { | |
my $speed = $1; | |
$speed =~ s/,//g; | |
$result->{"bytes/sec"} = $speed; | |
} | |
else { | |
die "output format error"; | |
} | |
push(@result, $result); | |
} | |
rsync($WEBARENA_IPV4); | |
{ | |
open (my $wr,">>:utf8", $RESULT_FILE) or die $!; | |
my @order = qw(time host bytes/sec); | |
say $wr join(",", @order) if -z $RESULT_FILE; | |
for my $r (@result){ | |
my @line; | |
push(@line, $r->{$_}) for @order; | |
say "csvline = " . join(",", @line); | |
say $wr join(",", @line); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment