Skip to content

Instantly share code, notes, and snippets.

@yaasita
Created November 24, 2022 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaasita/cc962c52a98b250aa67bf3952bd84b40 to your computer and use it in GitHub Desktop.
Save yaasita/cc962c52a98b250aa67bf3952bd84b40 to your computer and use it in GitHub Desktop.
#!/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