-
Notifications
You must be signed in to change notification settings - Fork 12
/
cl-gatherfile.pl
executable file
·92 lines (69 loc) · 2.42 KB
/
cl-gatherfile.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env perl
$|++;
###########################################################################
# #
# Cluster Tools: cl-gatherfile.pl #
# Copyright 2007-2011, Albert P. Tobey <tobert@gmail.com> #
# #
###########################################################################
=head1 NAME
cl-gatherfile.pl - harvest files from remote systems
=head1 SYNOPSIS
cl-gatherfile.pl [-a] -r $REMOTE_FILENAME -l $LOCAL_DIRECTORY
-r: remote file to gather
-l: local directory to write files to
-a: append the hostname to the filename when writing it locally
-d: only gather from hosts
-n: number of hosts to gather from
-v: verbose mode
-h: show this help text\n
=cut
use Pod::Usage;
use File::Temp qw/tempfile/;
use File::Basename;
use Getopt::Long;
use strict;
use warnings;
use FindBin qw($Bin);
use lib $Bin;
use DshPerlHostLoop;
our $host_cmd = undef;
our $local_dir = undef;
our $remote_file = undef;
our $append_hostname = undef;
our $help = undef;
GetOptions(
"l=s" => \$local_dir,
"r=s" => \$remote_file,
"a" => \$append_hostname,
"d" => \$host_cmd,
"h" => \$help
);
unless ( ($local_dir && $remote_file && -r $local_dir) || $help ) {
pod2usage();
}
unless ( -d $local_dir || mkdir($local_dir) ) {
pod2usage( -message => "Local directory '$local_dir' does not exist and could not be created." );
}
func_loop( \&runit );
sub runit {
my $host = shift;
my $remote = "$remote_user\@$host:$remote_file";
my $dest = $local_dir;
if ( $append_hostname ) {
my $file = basename( $remote_file );
$dest = "$local_dir/$host-$file";
}
print STDERR "Command($$): /usr/bin/scp -q $ssh_options $remote $dest\n" if ( verbose() );
system( "/usr/bin/scp -q $ssh_options $remote $dest" );
}
exit 0;
# vim: et ts=4 sw=4 ai smarttab
__END__
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2007-2011 by Al Tobey.
This is free software; you can redistribute it and/or modify it under the terms
of the Artistic License 2.0. (Note that, unlike the Artistic License 1.0,
version 2.0 is GPL compatible by itself, hence there is no benefit to having an
Artistic 2.0 / GPL disjunction.) See the file LICENSE for details.
=cut