#!/usr/bin/perl
$HUMAX="root\@humax";
$XFER="/media/ext3/"; #path to the media with decoded recordings
$RECORDINGS="/mnt/hd2/My Video/"; #path to original recording
$UPLD="intransit/";#path to holding area
$DONE="edit/";#when successfully uploaded move here
$SSH="ssh $HUMAX";#command to execute secure shell to HUMAX box
$SCP="scp $HUMAX:";#command to copy using scp from HUMAX box
$ARCHIVED="/mnt/hd2/My Video/ARCHIVED/";#move files successfully uploaded to here
#########################
### DO NOT EDIT BELOW ###
#########################
if ( $ARGV[0]=~ "-help" ){
print <<EOF;
This purpose of this script it to archive recordings off the HDR FOX T2
that have been sucessfully copied to the archive media $XFER directory.
The script checks that the files in the $XFER directory are also located
somewhere in the $RECORDINGS directory (main directory where recording
are stored).
Upon sucessfully copying of the files in the $XFER directory the files
are deleted and the files on the main video library $RECORDINGS are
moved to the $ARCHIVED directory.
EOF
}
print "\nLook to see what has been uploaded so far ...\n";
open(INTRANSIT,"find \"$UPLD\" -name \"*.ts\" -exec ls -l {} \\; |");
while(<INTRANSIT>){
chomp;
$fn = substr($_,index($_,$UPLD)+length($UPLD));
split;
$uploaded{$fn}=@_[4];
print $fn," of size : $uploaded{$fn}\n";
}
close INTRANSIT;
print "\nLook to see what's new on box ...\n";
open(NEW,"$SSH 'find \"$XFER\" -name \"*.ts\"'|");
while(<NEW>){
chomp;
$fn=substr($_,length($XFER));
print $fn,"\n";
$new{$fn}=-1;
}
close NEW;
print "\nGet sizes of new files...\n";
foreach $f (keys %new){
open(SZ,"$SSH 'ls -l \"$XFER".$f."\"'|");
while(<SZ>){
if($_ =~ $f){split;$new{$f}=@_[4]};
}
print "$f size = $new{$f}\n";
}
print "\nFound new files, let's check if there complete...\n";
open(ALL,"$SSH 'find \"$RECORDINGS\" -name \"*.ts\"'|");
while(<ALL>){
chomp;
$exists{$_}=$_;
}
close ALL;
foreach $f (keys %exists){
foreach $n (keys %new){
if($f =~ $n){
print "$n found, check sizes ... ";
open(SZ,"$SSH 'ls -l \"".$exists{$f}."\"'|");
while(<SZ>){
if($_ =~ $n){
split;
$exists{$f}=@_[4];
print "its size is :: $exists{$f}";
}
}
print "\n";
if($new{$n} == $exists{$f}){
print "\nCheck $n uploaded and if so delete off humax...\n";
if($new{$n} == $uploaded{$n}){
print "Removing $n and archiving on humax...\n";
system "$SSH 'rm -f \"".$XFER.substr($n,0,length($n)-2)."\"*'\n";
system "$SSH 'mv -f \"".substr($f,0,length($f)-2)."\"* \"$ARCHIVED\"'\n";
system "mv -f \"".$UPLD.substr($n,0,length($n)-2)."\"* $DONE\n";
}else{
print "\nUpload from humax :: $n\n";
system "$SCP'\"$XFER$n\"' $UPLD";
}
}
}
}
}
print "All done...\n";
exit 0;