Handle hostnames with upper-case letters
[webmin.git] / cluster-copy / copy.pl
1 #!/usr/local/bin/perl
2 # cron.pl
3 # Run a command on multiple servers at once
4
5 $no_acl_check++;
6 require './cluster-copy-lib.pl';
7
8 $copy = &get_copy($ARGV[0]);
9 $copy || die "Copy ID $ARGV[0] does not exist!";
10 $ENV{'SERVER_ROOT'} = $root_directory;  # hack to make 'this server' work
11 $status = "succeeded";
12 &run_cluster_job($copy, \&callback);
13
14 if ($copy->{'email'}) {
15         # Email off status message
16         &foreign_require("mailboxes", "mailboxes-lib.pl");
17
18         # Construct and send the email
19         local $from = $config{'from'} || &mailboxes::get_from_address();
20         local @files = split(/\t+/, $copy->{'files'});
21         local $subject = &text('email_subject_'.$status, join(", ", @files));
22         &mailboxes::send_text_mail($from, $copy->{'email'}, undef, $subject,
23                                    $results);
24         }
25
26 # callback(error, &server, message, dirs, command-output)
27 sub callback
28 {
29 local $d = $_[1]->{'desc'} || $_[1]->{'host'};
30 if (!$_[0]) {
31         # Failed - show error
32         $results .= &text('exec_on', $d, $_[2])."\n\n";
33         $status = "failed";
34         }
35 else {
36         if ($_[6]) {
37                 # Show pre command output
38                 $results .= &text('exec_before', $d)."\n";
39                 $results .= $_[6];
40                 $results .= "\n";
41                 }
42         if (@{$_[4]}) {
43                 # Show created directories
44                 $results .= &text('exec_made', $d)."\n";
45                 foreach $f (@{$_[4]}) {
46                         $results .= "    $f\n";
47                         }
48                 $results .= "\n";
49                 }
50         if (!@{$_[2]}) {
51                 # Nothing copied
52                 $results .= &text('exec_nothing', $d)."\n";
53                 }
54         else {
55                 # Show output if any
56                 $results .= &text('exec_success', $d)."\n";
57                 foreach $f (@{$_[2]}) {
58                         $results .= "    $f\n";
59                         }
60                 $results .= "\n";
61                 }
62         if (@{$_[3]}) {
63                 # Show error files
64                 $results .= &text('exec_not', $d)."\n";
65                 foreach $f (@{$_[3]}) {
66                         $results .= "    $f->[0] : $f->[1]\n";
67                         }
68                 $results .= "\n";
69                 }
70         if ($_[5]) {
71                 # Show post command output
72                 $results .= &text('exec_cmd', $d)."\n";
73                 $results .= $_[5];
74                 $results .= "\n";
75                 }
76         }
77 }
78