3 # Actually run the command on all servers and show the output
5 require './cluster-shell-lib.pl';
7 &error_setup($text{'run_err'});
10 # Just clearing history
11 &lock_file($commands_file);
12 unlink($commands_file);
13 &unlock_file($commands_file);
19 $in{'cmd'} ||= $in{'old'};
20 $in{'cmd'} =~ /\S/ || &error($text{'run_ecmd'});
22 # Build the list of servers
23 @servers = &servers::list_servers();
24 @sel = split(/\0/, $in{'server'});
27 push(@run, grep { $_->{'user'} } @servers);
29 elsif ($s =~ /^group_(.*)$/) {
30 # All members of a group
31 ($group) = grep { $_->{'name'} eq $1 }
32 &servers::list_all_groups(\@servers);
33 foreach $m (@{$group->{'members'}}) {
34 push(@run, grep { $_->{'host'} eq $m && $_->{'user'} }
40 push(@run, ( { 'desc' => $text{'index_this'} } ));
43 # A single remote server
44 push(@run, grep { $_->{'host'} eq $s } @servers);
48 @run || &error($text{'run_enone'});
50 &ui_print_header(undef, $text{'run_title'}, "");
52 # Setup error handler for down hosts
55 $inst_error_msg = join("", @_);
57 &remote_error_setup(\&inst_error);
59 # Run one each one in parallel and display the output
62 local ($rh = "READ$p", $wh = "WRITE$p");
64 select($wh); $| = 1; select(STDOUT);
66 # Do the install in a subprocess
69 &remote_foreign_require($s->{'host'}, "webmin",
71 if ($inst_error_msg) {
72 # Failed to contact host ..
73 print $wh &serialise_variable([ 0, $inst_error_msg ]);
77 # Run the command and capture output
78 local $q = quotemeta($in{'cmd'});
79 local $rv = &remote_eval($s->{'host'}, "webmin",
80 "\$x=`($q) </dev/null 2>&1`");
82 print $wh &serialise_variable([ 1, $rv ]);
90 # Get back all the results
96 local $rv = &unserialise_variable($line);
98 local $d = $s->{'desc'} || $s->{'host'};
101 # Comms error with subprocess
102 print "<b>",&text('run_failed', $d, "Unknown reason"),
106 # Error with remote server
107 print "<b>",&text('run_failed', $d, $rv->[1]),"</b><p>\n";
111 print "<b>",&text('run_success', $d),"</b>\n";
112 print "<ul><pre>".&html_escape($rv->[1])."</pre></ul><p>\n";
117 # Save command and server
118 &open_lock_tempfile(COMMANDS, ">>$commands_file");
119 &print_tempfile(COMMANDS, $in{'cmd'},"\n");
120 &close_tempfile(COMMANDS);
121 $config{'server'} = join(" ", @sel);
122 &save_module_config();
124 &webmin_log("run", undef, undef, { 'cmd' => $in{'cmd'},
125 'run' => [ map { $_->{'host'} } @run ] });
127 &ui_print_footer("", $text{'index_return'});