- #!/usr/bin/perl
- use 5.14.0;
- use strict;
- use warnings;
- sub usage {
- say "Usage: " . basename($0) . " [ infile ] [ outdir ]";
- exit;
- }
- if (!$ARGV[0] || !$ARGV[1]) { usage(); }
- elsif (! -f $ARGV[0] || ! -d $ARGV[1]) { usage(); }
- my $infile = abs_path($ARGV[0]);
- my $outfile;
- my $outdir = abs_path($ARGV[1]);
- `df --block-size=1 "$outdir" | tail --lines 1`));
- say "$free megabytes free in $outdir";
- say "$infile is $size megabytes";
- if ($size > $free) {
- say "Not enough free space in '$outdir'";
- exit;
- }
- if ($size > $limit) {
- my $parts = ceil(( $size / $limit ));
- my $last = $parts;
- my $skip = 0;
- foreach my $n (1 .. $parts) {
- $outfile = $outdir . '/' . basename($infile) . '.part' .
- $n;
- if (-f $outfile) {
- say "${outfile}: already exists!";
- exit;
- }
- say "${outfile}: writing...";
- if ($n == 1) {
- 'bs=1MB', 'count=' . $limit);
- $skip += $limit;
- } elsif ($n == $last) {
- 'bs=1MB', 'skip=' . "$skip");
- } else {
- 'bs=1MB', 'skip=' . "$skip", 'count=' . $limit);
- $skip += $limit;
- }
- if ($? != 0 && $? != 2) {
- say "Something went wrong with 'dd': $!";
- exit;
- } elsif ($? == 2) {
- say "Interrupted by user!";
- exit;
- }
- }
- } else {
- $outfile = $outdir . '/' . basename($infile);
- if (! -f $outfile) {
- say "${outfile}: writing...";
- }
- say "\nDone copying file!";
FAT32 copy perl script
Posted by Anonymous on Tue 18th Sep 2012 03:56
raw | new post
modification of post by Anonymous (view diff)
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.