This is a test script I wrote to download a file from an URL.
The URL must be a direct link to the download file, and depending on the time provided, the program will count down and download at the specified time.
The problem is, it works for smaller file (~kb), but when I try for big files it freezes.
my $url = 'http://releases.ubuntu.com/14.04.2/ubuntu-14.04.2-desktop-amd64.iso';
my $file = '//strawberry//myscripts//ubuntu-14.04.2-desktop-amd64.iso';
my $starttime = '08.07.15 11:43:11';
my $nowtime = time; # time in sec since 1970
my $sTime = 0;
my $sleepSec = 0;
# parsing the input (start) time
if ( $starttime =~ /^\s*(\d{1,2})\.(\d{1,2})\.(\d{2})\s+(\d{1,2})\:(\d{1,2})\:(\d{1,2})/ ) {
# mktime(sec,min,hr,day,month,year)
# month (0..11); year = 0 => 1900 , year = 100 => 2000
$sTime = mktime( $6, $5, $4, $1, $2 - 1, 100 + $3 );
}
print "\nNow, the time is ---", ctime( $nowtime );
print "\nDownload will start at ---", ctime( $sTime );
$sleepSec = difftime( $sTime, $nowtime );
if ( $sleepSec > 0 ) {
print "I will sleep for $sleepSec seconds, and then download it. zzZ\n";
my $num = $sleepSec;
while ( $num-- ) {
sleep( 1 );
$| = 1;
print "$num\r";
}
my $status = getstore( $url, $file );
die "Error $status on $url" unless is_success( $status );
print "Your file has been downloaded successfully.\n";
}
else {
print "Shit I missed my starttime...\n";
}