@@ -23,6 +23,7 @@ =head1 SYNOPSIS
23
23
cl-sendfile.pl [-l $LOCAL_FILE] [-r $REMOTE_FILE] [-h] [-v] [--incl <pattern>] [--excl <pattern>]
24
24
-l: local file/directory to rsync - passed through unmodified to rsync
25
25
-r: remote location for rsync to write to - also unmodified
26
+ -x: stage the file as a normal user and relocate using sudo (requires sudo root/NOPASSWD)
26
27
-v: verbose output
27
28
-h: print this message
28
29
=cut
@@ -42,10 +43,13 @@ =head1 SYNOPSIS
42
43
our $local_file = undef ;
43
44
our $remote_file = undef ;
44
45
our $help = undef ;
46
+ our $sudo = undef ;
47
+ our $final_file = undef ;
45
48
46
49
GetOptions(
47
50
" l=s" => \$local_file ,
48
51
" r=s" => \$remote_file ,
52
+ " x" => \$sudo ,
49
53
" h" => \$help
50
54
);
51
55
@@ -57,17 +61,25 @@ =head1 SYNOPSIS
57
61
pod2usage();
58
62
}
59
63
60
- # save all the files sent out to a local tree so it's easy to reproduce the cluster
61
- # my $dir = dirname( $remote_file );
62
- # system( "mkdir -p $ENV{HOME}/files/$dir" );
63
- # copy( $local_file, "$ENV{HOME}/files/$remote_file" );
64
-
65
- my $routine = sub {
66
- my $hostname = shift ;
67
- scp( $local_file , " $hostname :$remote_file " );
68
- };
64
+ $final_file = $remote_file ;
65
+ if ( $sudo ) {
66
+ (my $fh , $remote_file ) = my_tempfile();
67
+ close $fh ;
68
+ unlink $remote_file ;
69
+ }
69
70
70
- func_loop( $routine );
71
+ func_loop(sub {
72
+ my $host = shift ;
73
+ scp( $local_file , " $host :$remote_file " );
74
+ });
75
+
76
+ if ( $sudo ) {
77
+ func_loop(sub {
78
+ my $host = shift ;
79
+ ssh( " $remote_user \@ $host " , " sudo cp $remote_file $final_file " );
80
+ ssh( " $remote_user \@ $host " , " rm $remote_file " );
81
+ });
82
+ }
71
83
72
84
# vim: et ts=4 sw=4 ai smarttab
73
85
0 commit comments