Skip to content

Instantly share code, notes, and snippets.

@jcreasey
Created June 26, 2014 06:37
Show Gist options
  • Save jcreasey/7935778dffc18ee8d523 to your computer and use it in GitHub Desktop.
Save jcreasey/7935778dffc18ee8d523 to your computer and use it in GitHub Desktop.
Script to copy a file showing progress.
#!/usr/bin/perl
use strict;
use warnings;
use POSIX ":sys_wait_h";
my $from = $ARGV[0];
my $to = $ARGV[1];
print "Copying $from to $to\n";
$| = -1;
my $pid = fork;
if ($pid) {
print "parent\n";
} elsif ($pid == 0) {
system "cp $from $to";
exit 0;
} else {
die "Couldnt fork\n";
}
my $child;
do {
$child = waitpid(-1, WNOHANG);
sleep 1;
print `ls -al $to`;
print "-";
} while $child >= 0;
print "\nFile has been copied.\n";
@jcreasey
Copy link
Author

Call this script copy_file.pl
Run it like this:
./copy_file /tmp/from_file /tmp/to_file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment