Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a40e1bc0fd | ||
|
|
77f295ba56 | ||
|
|
f4b32c93da | ||
|
|
b685d21e3f | ||
|
|
034afa8b53 | ||
|
|
2d87c5392c | ||
|
|
4f2d382916 | ||
|
|
93a95bc70f |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
testfolder/*
|
||||||
|
test*.txt
|
||||||
76
README.md
76
README.md
@@ -1,2 +1,78 @@
|
|||||||
# transfer_scripts
|
# transfer_scripts
|
||||||
A few scripts for estimating size and transferring files
|
A few scripts for estimating size and transferring files
|
||||||
|
|
||||||
|
## Function
|
||||||
|
|
||||||
|
transfer.pl - Use rsync to copy over files in a list or directory.
|
||||||
|
|
||||||
|
estimate.pl - Estimate the total size of a list of files or a directory.
|
||||||
|
|
||||||
|
fixlist.sh - fix your file list to the format these programs expect
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
These scripts are used as follows:
|
||||||
|
|
||||||
|
|
||||||
|
$ transfer.pl
|
||||||
|
Usage: --file= --host= --directory= --user= --dest= --flags= [--verbose] [--help]
|
||||||
|
|
||||||
|
--file - Input file to read with list of files/folders to transfer
|
||||||
|
|
||||||
|
--host - IP address or hostname of the remote system
|
||||||
|
|
||||||
|
--directory - Relative or absolute path to the folder containing the files/folders to transfer,
|
||||||
|
|
||||||
|
with no trailing slash
|
||||||
|
|
||||||
|
--user - User account on the remote system to use
|
||||||
|
|
||||||
|
--dest - Destination on the remote system to copy files to
|
||||||
|
|
||||||
|
--flags - rsync flags to use when copying the files over
|
||||||
|
|
||||||
|
--verbose - run rsync with -vvv
|
||||||
|
|
||||||
|
--help - show this help
|
||||||
|
|
||||||
|
|
||||||
|
$ estimate.pl
|
||||||
|
Usage: [--dir=] [--infile=] [--help]
|
||||||
|
|
||||||
|
--dir - directory to estimate the size of
|
||||||
|
|
||||||
|
--infile - file with a list of filenames to estimate the size of
|
||||||
|
|
||||||
|
--prefix - prefix path for filenames in the infile
|
||||||
|
|
||||||
|
--help - print this help
|
||||||
|
|
||||||
|
|
||||||
|
$ fixlist.sh
|
||||||
|
Usage: /usr/local/bin/fixlist.sh <filename>
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Feel free to fork and submit pull requests, I will review them and merge into main if I like them. If you do submit a pull request,
|
||||||
|
please also email me at elia@sassysalamander.net so I can look at it faster.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Affero General Public License 3.0
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as
|
||||||
|
published by the Free Software Foundation, either version 3 of the
|
||||||
|
License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
## Copyright
|
||||||
|
|
||||||
|
2024 Elia Farin <elia@sassysalamander.net>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
#
|
#
|
||||||
# Author: Elia Farin 2024
|
# Author: Elia Farin
|
||||||
# Written: 8/9/24
|
# Written: 8/9/24
|
||||||
# Modified: 8/9/24
|
# Modified: 8/9/24
|
||||||
# License: AGPL-3.0-or-later
|
# License: AGPL-3.0-or-later
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
# Modified: 8/9/24
|
# Modified: 8/9/24
|
||||||
# License: AGPL-3.0-or-later
|
# License: AGPL-3.0-or-later
|
||||||
#
|
#
|
||||||
# Copyright (C) 2024 Elia Farin
|
# Copyright (C) 2024 Elia Farin
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# it under the terms of the GNU Affero General Public License as
|
||||||
@@ -19,7 +19,8 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#
|
||||||
if [ -z "${1}" ]; then
|
if [ -z "${1}" ]; then
|
||||||
echo "Usage: ${0} <filename>"
|
echo "Usage: ${0} <filename>"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -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
|
||||||
50
transfer.pl
50
transfer.pl
@@ -1,9 +1,4 @@
|
|||||||
#!/usr/local/bin/perl
|
#!/usr/bin/env perl
|
||||||
|
|
||||||
use strict;
|
|
||||||
use Getopt::Long;
|
|
||||||
use Proc::Pidfile;
|
|
||||||
|
|
||||||
# Transfer script transfer.pl
|
# Transfer script transfer.pl
|
||||||
# Author: Elia Farin
|
# Author: Elia Farin
|
||||||
# Written: 8/9/24
|
# Written: 8/9/24
|
||||||
@@ -25,25 +20,16 @@ use Proc::Pidfile;
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
my $pidfile;
|
use strict;
|
||||||
# if we are root, create a pidfile
|
use Getopt::Long;
|
||||||
if ($> = 0) {
|
|
||||||
my $pp = Proc::Pidfile->new( pidfile => "/var/run/transfer.pl.pid" );
|
|
||||||
} else {
|
|
||||||
# if not, create our home pidfile
|
|
||||||
my $home = $ENV("$HOME");
|
|
||||||
my $pp = Proc::Pidfile->new( pidfile => "$home/transfer.pl.pid");
|
|
||||||
}
|
|
||||||
|
|
||||||
# die if we cannot get pidfile lock
|
|
||||||
$pidfile = $pp->$pidfile();
|
|
||||||
|
|
||||||
# sane defaults
|
# sane defaults
|
||||||
my $file = "";
|
my $file = "";
|
||||||
my $host = "192.168.42.100";
|
my $host = "";
|
||||||
my $directory = ".";
|
my $directory = ".";
|
||||||
my $user = "char";
|
my $user = getlogin() || (getpwuid($<))[0] || $ENV{LOGNAME} || $ENV{USER};
|
||||||
my $dest= "/home/char/Downloads/";
|
my $dest= "/home/$user/Downloads/";
|
||||||
my $flags = "rvz";
|
my $flags = "rvz";
|
||||||
my $verbose;
|
my $verbose;
|
||||||
my $help;
|
my $help;
|
||||||
@@ -58,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) {
|
||||||
@@ -66,30 +53,45 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
# remove the pidfile
|
|
||||||
undef $pp;
|
|
||||||
|
|
||||||
# help subroutine
|
# help subroutine
|
||||||
sub help {
|
sub help {
|
||||||
print "Usage: $ARGV[0] --file= --host= --directory= --user= --dest= --flags= [--verbose] [--help]\n
|
print "Usage: $ARGV[0] --file= --host= --directory= --user= --dest= --flags= [--verbose] [--help]\n
|
||||||
|
|||||||
Reference in New Issue
Block a user