3
use vars qw($VERSION $Timeout $Flush $PreserveDuringSCP $RecurseDuringSCP);
9
$PreserveDuringSCP = 1;
10
$RecurseDuringSCP = 0;
12
use POSIX ":sys_wait_h";
13
use Mycat::TraceMessages qw(t tt ttt p pe);
15
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; # Make %ENV safer
16
$ENV{'PATH'} = '/bin:/usr/bin';
22
Mycat::scp - Perl extension for MySQL Cluster Administration Tools
26
Mycat is a collection of utilities for use in monitoring database clusters.
30
# specify options to SCP
31
$Mycat::scp::PreserveDuringSCP = 1; // preserve file modification times
32
$Mycat::scp::RecurseDuringSCP = 0; // do not recursively copy directories
34
# instantiate Mycat::scp objects
35
my $s = Mycat::scp::new('/path/to/local/file','[user@]host:/path/to/[file]');
37
# execute copy and retrieve result when finished
38
$Mycat::scp::Flush = 0;
39
my $result = $s->execute();
42
# alternately, print results as they come back from remote server
43
$Mycat::scp::Flush = 1;
55
=item Mycat::scp::new($origin,$destination)
57
Initialize a new scp object.
58
Both parameters are required.
59
This function merely instantiates the object for further use.
61
my $s = Mycat::scp::new('/path/to/local/file','[user@]host:/path/to/[file]');
68
$self->{origin} = shift or die("Mycat::scp::new called without origin");
69
$self->{destin} = shift or die("Mycat::scp::new called without destination");
70
$self->{result} = undef;
71
bless ($self, $class);
75
# Mycat::scp::execute {{{
80
This is the workhorse of Mycat's SCP functions, spawning a child process to
81
encapsulate the SCP connection, passing the result back through shared memory.
83
Timeout can be controlled via the variable ::Timeout, default is 10sec
85
To see the internal workings of this function, turn trace debugging to level 3.
95
if ( $PreserveDuringSCP or $RecurseDuringSCP ) {
97
$options .= 'p' if $PreserveDuringSCP;
98
$options .= 'r' if $RecurseDuringSCP;
101
tt('SCP: Copying ['.$self->{origin}.'] to ['.$self->{destin}.']...');
105
if ( defined($options) ) {
106
$childpid = open KID, '-|', 'scp', $options, $self->{origin}, $self->{destin};
108
$childpid = open KID, '-|', 'scp', $self->{origin}, $self->{destin};
111
ttt('SCP: forked and waiting for subprocess to finish');
117
local $SIG{ALRM} = sub { pe('Sending kill (9) signal to SCP after waiting '.$Timeout.' seconds'); kill 9, $childpid; };
118
alarm $Timeout unless $Timeout == 0;
120
$self->{result} .= $_;
129
close KID || pe('SCP exited with abnormal status: '.$?);
131
return $self->{result};
140
Devananda van der Veen
141
devananda.vdv@gmail.com