Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a40e1bc0fd | ||
|
|
77f295ba56 | ||
|
|
f4b32c93da | ||
|
|
b685d21e3f | ||
|
|
034afa8b53 | ||
|
|
2d87c5392c |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
testfolder/*
|
||||||
|
test*.txt
|
||||||
@@ -30,3 +30,5 @@ cp ./fixlist.sh /usr/local/bin/fixlist.sh
|
|||||||
chmod 755 /usr/local/bin/transfer.pl
|
chmod 755 /usr/local/bin/transfer.pl
|
||||||
chmod 755 /usr/local/bin/estimate.pl
|
chmod 755 /usr/local/bin/estimate.pl
|
||||||
chmod 755 /usr/local/bin/fixlist.sh
|
chmod 755 /usr/local/bin/fixlist.sh
|
||||||
|
|
||||||
|
cpan install Getopt::Long
|
||||||
30
transfer.pl
30
transfer.pl
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/local/bin/perl
|
#!/usr/bin/env perl
|
||||||
# Transfer script transfer.pl
|
# Transfer script transfer.pl
|
||||||
# Author: Elia Farin
|
# Author: Elia Farin
|
||||||
# Written: 8/9/24
|
# Written: 8/9/24
|
||||||
@@ -22,15 +22,14 @@
|
|||||||
#
|
#
|
||||||
use strict;
|
use strict;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
use re;
|
|
||||||
my $username = getlogin() || (getpwuid($<))[0] || $ENV{LOGNAME} || $ENV{USER};
|
|
||||||
|
|
||||||
# sane defaults
|
# sane defaults
|
||||||
my $file = "";
|
my $file = "";
|
||||||
my $host = "";
|
my $host = "";
|
||||||
my $directory = ".";
|
my $directory = ".";
|
||||||
my $user = $username;
|
my $user = getlogin() || (getpwuid($<))[0] || $ENV{LOGNAME} || $ENV{USER};
|
||||||
my $dest= "/home/$username/Downloads/";
|
my $dest= "/home/$user/Downloads/";
|
||||||
my $flags = "rvz";
|
my $flags = "rvz";
|
||||||
my $verbose;
|
my $verbose;
|
||||||
my $help;
|
my $help;
|
||||||
@@ -45,6 +44,7 @@ my $result = GetOptions ( "file=s" => \$file,
|
|||||||
"verbose" => \$verbose,
|
"verbose" => \$verbose,
|
||||||
"help" => \$help);
|
"help" => \$help);
|
||||||
|
|
||||||
|
print "file: $file, host: $host, directory: $directory, user: $user, dest: $dest flags: $flags verbose: $verbose help: $help\n";
|
||||||
### Begin main logic
|
### Begin main logic
|
||||||
# help catch
|
# help catch
|
||||||
if ($help) {
|
if ($help) {
|
||||||
@@ -53,24 +53,42 @@ if ($help) {
|
|||||||
}
|
}
|
||||||
# If we have all the right arguments, begin the copy
|
# If we have all the right arguments, begin the copy
|
||||||
elsif (length $file && length $host && length $user && length $dest && length $directory) {
|
elsif (length $file && length $host && length $user && length $dest && length $directory) {
|
||||||
|
#print "in elsif block\n";
|
||||||
# Open our filehandle
|
# Open our filehandle
|
||||||
open my $info, $file or die "Could not open $file: $!";
|
open my $info, $file or die "Could not open $file: $!";
|
||||||
|
|
||||||
|
|
||||||
|
my $linenum = 0;
|
||||||
|
while( my $iterline = <$info>) {
|
||||||
|
#print "in first while loop\n";
|
||||||
|
$linenum++;
|
||||||
|
}
|
||||||
|
close $file;
|
||||||
|
|
||||||
|
open $info, $file or die "Could not open $file: $!";
|
||||||
|
my $xfernum = 0;
|
||||||
# read line by line
|
# read line by line
|
||||||
while( my $line = <$info> ) {
|
while( my $line = <$info> ) {
|
||||||
|
#print "in second while loop\n";
|
||||||
|
$xfernum++;
|
||||||
chomp $line;
|
chomp $line;
|
||||||
# actual copy logic
|
# actual copy logic
|
||||||
if (length $verbose) {
|
if (length $verbose) {
|
||||||
|
#print "in verbose section";
|
||||||
|
print "\n\nTransferring object $xfernum of $linenum\n\n";
|
||||||
system("rsync", "-vvv", "-$flags", "$directory/$line", "$user\@$host:$dest");
|
system("rsync", "-vvv", "-$flags", "$directory/$line", "$user\@$host:$dest");
|
||||||
} else {
|
} else {
|
||||||
|
#print "in non-verbose section";
|
||||||
|
print "\n\nTransferring object $xfernum of $linenum\n\n";
|
||||||
system("rsync", "-$flags", "$directory/$line", "$user\@$host:$dest");
|
system("rsync", "-$flags", "$directory/$line", "$user\@$host:$dest");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close $file;
|
||||||
|
|
||||||
}
|
}
|
||||||
# if we fail the variables check, print usage help
|
# if we fail the variables check, print usage help
|
||||||
else {
|
else {
|
||||||
|
#print "In help else\n";
|
||||||
help();
|
help();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user