Created
June 26, 2014 06:37
-
-
Save jcreasey/7935778dffc18ee8d523 to your computer and use it in GitHub Desktop.
Script to copy a file showing progress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Call this script copy_file.pl
Run it like this:
./copy_file /tmp/from_file /tmp/to_file