直前のスクリプトをcrawl.plと保存して
自分の管理してるサーバーに実行させよう。
#!/usr/bin/env perl use strict; use warnings; use FindBin; use Perl6::Say; use Net::SSH::Perl; use IO::All; my @hosts = qw/ too.foo.bar many.foo.bar secret.foo.bar /; my $user = "bokutin"; my $cmd = "/usr/bin/perl"; #my $stdin = "print 'test';"; my $stdin = io("$FindBin::Bin/crawl.pl")->slurp; for my $host (@hosts) { my $ssh = Net::SSH::Perl->new($host, protocol => 2, identity_files => ["$ENV{HOME}/.ssh/id_rsa"], ); $ssh->login($user); my($stdout, $stderr, $exit) = eval { $ssh->cmd($cmd, $stdin) }; if ($@) { print "$host: connecting error.\n"; } else { print "$host:\n"; for (split("\n", $stdout || "")) { print "\tSTDOUT: $_\n"; } for (split("\n", $stderr || "")) { print "\tSTDERR: $_\n"; } print "\tEXIT CODE: $exit\n"; } } say "succeed";
コメントする