| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | #use Smart::Comments::JSON '##'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use lib 'lib'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Net::OpenSSH; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use Term::ReadKey; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use SSH::Batch::ForNodes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use File::Temp qw/ :POSIX /; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use Time::HiRes qw/sleep/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | sub help ($); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | sub check_openssh_version ($); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 7 | ▶ | if (!@ARGV) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | warn "No argument specified.\n\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | help(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 6 | my $list_hosts_only = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 6 | my ($user, $port, $timeout, $verbose, $ask_for_pass, $ask_for_passphrase); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 6 | my $concurrency = 20; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | my (@cmd, @exprs, $ssh_cmd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 6 | $ssh_cmd = $ENV{SSH_BATCH_SSH_CMD}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 6 | my $fetch_value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | my $found_sep; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | my $last_option; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | my $use_tty; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | my $use_quiet_mode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | my $line_mode = $ENV{SSH_BATCH_LINE_MODE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | for (@ARGV) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 36 | ▶ | if (defined $fetch_value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | $fetch_value->($_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | undef $fetch_value; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 35 | ▶ | if ($_ eq '--') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | @cmd = @exprs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | @exprs = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | $found_sep = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 33 | ▶ | if (/^-(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | my $group = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 6 | ▶ | if ($group eq 'l') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 13 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | $list_hosts_only = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } elsif ($group eq 'u') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | $fetch_value = sub { $user = shift }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } elsif ($group eq 't') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $fetch_value = sub { $timeout = shift }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } elsif ($group eq 'h') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | help(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } elsif ($group eq 'p') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | $fetch_value = sub { $port = shift }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } elsif ($group eq 'v') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 2 | $verbose = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } elsif ($group eq 'w') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $ask_for_pass = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | } elsif ($group eq 'P') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $ask_for_passphrase = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } elsif ($group eq 'c') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $fetch_value = sub { $concurrency = shift }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } elsif ($group eq 'ssh') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | $fetch_value = sub { $ssh_cmd = shift }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } elsif ($group eq 'L') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | $line_mode = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } elsif ($group eq 'tty') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $use_tty = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } elsif ($group eq 'q') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $use_quiet_mode = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | die "Unknown option: $_\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | $last_option = $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 27 | push @exprs, $_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | ▶ | if (defined $fetch_value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | die "ERROR: Option $last_option takes a value.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 5 | ▶ | if (!$found_sep && !@cmd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$found_sep or @cmd
MC/DC50%1/2
$found_sep or @cmd
$found_sep
@cmd
Truth table66%2/3
A or B
A= $found_sepB= @cmd
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | push @cmd, shift @exprs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 5 | ▶ | if (!@cmd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | die "No command specified.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 4 | ▶ | if ($verbose) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | warn "Command: ", (map { "[$_]" } @cmd), "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | ▶ | if (defined $ssh_cmd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | warn "Using SSH program [$ssh_cmd].\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | ▶ | check_openssh_version($ssh_cmd || 'ssh'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$ssh_cmd || 'ssh'
MC/DC100%1/1
$ssh_cmd || 'ssh'
$ssh_cmd
Truth table100%2/2
A
A= $ssh_cmd
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 4 | ▶ | if ($use_tty) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $concurrency = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | ▶ | if (!@exprs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | die "No cluster expression specified.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | my $expr = join ' ', @exprs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | ▶ | if ($verbose) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | warn "Cluster expression: $expr\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 3 | SSH::Batch::ForNodes::init_rc(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | my $set = SSH::Batch::ForNodes::parse_expr($expr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | ▶ | if ($set->is_empty) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | die "No machine to be operated.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | my @hosts = sort $set->elements; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | ▶ | if ($verbose) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | warn "Cluster set: @hosts\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } elsif ($list_hosts_only) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | print "Cluster set: @hosts\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | ▶ | if ($list_hosts_only) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | exit(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my ($passphrase, $password); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if ($ask_for_passphrase) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $passphrase = $ENV{SSH_BATCH_PASSPHRASE}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if (!$passphrase) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | print STDERR "Passphrase:"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ReadMode(2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | while (not defined ($passphrase = ReadLine(0))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ReadMode(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | chomp $passphrase; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if (!$passphrase) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | die "No passphrase specified.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | } elsif ($ask_for_pass) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $password = $ENV{SSH_BATCH_PASSWORD}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if (!$password) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | print STDERR "Password:"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ReadMode(2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | while (not defined ($password = ReadLine(0))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ReadMode(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | chomp $password; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if (!$password) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | die "No password specified.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my (%conns, @pids, @outs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my %pid2host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my $active_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | last if !@hosts && !@pids; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@hosts or @pids
MC/DC0%0/2
@hosts or @pids
@hosts
@pids
Truth table0%0/3
A or B
A= @hostsB= @pids
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | my @active_hosts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | while ($active_count < $concurrency) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | last if !@hosts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $host = shift @hosts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | my $ssh = Net::OpenSSH->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | $host, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | async => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | defined $timeout ? (timeout => $timeout) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | defined $user ? (user => $user) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | defined $port ? (port => $port) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | defined $passphrase ? (passphrase => $passphrase) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | defined $password ? (password => $password) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | defined $ssh_cmd ? (ssh_cmd => $ssh_cmd) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | $use_quiet_mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ? (master_opts => ["-q",], default_ssh_opts => ["-q",],) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if ($ssh->error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if ($line_mode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | print STDERR "$host: "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | print "===" x 7, " $host ", "===" x 7, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | warn "ERROR: Failed to establish SSH connection: ", | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | $ssh->error, "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $conns{$host} = $ssh; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $active_count++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | push @active_hosts, $host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | for my $host (@active_hosts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my ($out, $outfile) = tmpnam(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my $ssh = $conns{$host}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my $pid = $ssh->system({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | (defined $password? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | (stdin_data => "$password\n") : ()), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | stdout_fh => $out, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | stderr_to_stdout => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | async => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | defined $use_tty ? (tty => 1) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | }, @cmd); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | #warn "PID: $pid\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if (!defined $pid or $pid == -1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $pid or $pid == -1
MC/DC0%0/2
not defined $pid or $pid == -1
not defined $pid
$pid == -1
Truth table0%0/3
not(A) or B
A= not defined $pidB= $pid == -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | $active_count--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | ▶ | if ($line_mode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | print STDERR "$host: "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | print "===" x 7, " $host ", "===" x 7, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if ($ssh->error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | warn "ERROR: ", $ssh->error, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | warn "ERROR: Failed to spawn command.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | close $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | unlink $outfile; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | delete $conns{$host}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | push @outs, $outfile; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | push @pids, $pid; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $pid2host{$pid} = $host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if (@pids) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my $pid = shift @pids; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $host = delete $pid2host{$pid}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $active_count--; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | if (!$line_mode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | print "===" x 7, " $host ", "===" x 7, "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if (!defined $pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | warn "ERROR: Failed to connect to host $host.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | delete $conns{$host}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my $exit = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my $ret = waitpid($pid, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $exit = ($? >> 8); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | delete $conns{$host}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | unless ($ret > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | #redo if ($! == EINTR); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | warn "$host: ERROR: waitpid($pid) failed: $!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my $outfile = shift @outs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my $in; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | if (!open $in, $outfile) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | warn "ERROR: Can't open $outfile for reading: $!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | while (<$in>) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | if ($line_mode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | print "$host: "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | print "$_\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | ▶ | if ($exit > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if ($line_mode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | print STDERR "$host: "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | warn "Remote command returns status code $exit.\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | if (!$line_mode) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | close $in; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | unlink $outfile; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | ## HERE... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | sub help ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | ▶ | my $exit_code = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | my $msg = <<'_EOC_'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | USAGE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | atnodes [OPTIONS] COMMAND... -- HOST_PATTERN... [OPTIONS] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | atnodes [OPTIONS] COMMAND HOST_PATTERN... [OPTIONS] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | OPTIONS: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | -c <num> Set SSH concurrency limit. (default: 20, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | when -tty is on, this setting will no use) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | -h Print this help. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | -l List the hosts and do nothing else. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | -L Use the line-mode output format, i.e., prefixing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | every output line with the machine name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | (could be controlled by the env SSH_BATCH_LINE_MODE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | -p <port> Port for the remote SSH service. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | -ssh <path> Specify an alternate ssh program. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | (This overrides the SSH_BATCH_SSH_CMD environment.) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | -t <timeout> Specify timeout for net traffic. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | -u <user> User account for SSH login. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | -v Be verbose. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | -w Prompt for password (used for login and sudo, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | could be privided by SSH_BATCH_PASSWORD). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | -P Prompt for passphrase (used for login, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | could be privided by SSH_BATCH_PASSPHRASE). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | -tty Pseudo-tty. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | -q Run SSH in quiet mode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | _EOC_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | ▶ | if ($exit_code == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | print $msg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | exit(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 1 | warn $msg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | exit($exit_code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | sub check_openssh_version ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 4 | ▶ | my $ssh_cmd = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_openssh_version: called CC=5 SCAR=25.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 4 | my $version_info = `$ssh_cmd -V 2>&1`; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 4 | ▶ | if ($version_info && $version_info =~ /^OpenSSH_(\d+\.\d+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$version_info and $version_info =~ /^OpenSSH_(\d+\.\d+)/
MC/DC0%0/2
$version_info and $version_info =~ /^OpenSSH_(\d+\.\d+)/
$version_info
$version_info =~ /^OpenSSH_(\d+\.\d+)/
Truth table33%1/3
A and B
A= $version_infoB= $version_info =~ /^OpenSSH_(\d+\.\d+)/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my $v = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ($v && $v < 4.1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$v and $v < "4.1"
MC/DC0%0/2
$v and $v < "4.1"
$v
$v < "4.1"
Truth table0%0/3
A and B
A= $vB= $v < "4.1"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | die "OpenSSH version $v, should be >= 4.1!\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||