#!/usr/bin/perl
open(FP, "<ma");
$cmd = '-t';
if($#ARGV>0){
print "too many arguments\n";
print useage();
exit();
}elsif($#ARGV==0){
if($ARGV[0] eq '-t' || $ARGV[0] eq '-l' || $ARGV[0] eq '-d' || $ARGV[0] eq '-dd'){
$cmd = $ARGV[0];
}else{
print useage();
exit();
}
}
@filenames=();
while(<FP>){
chomp();
@video = split(/\|/);
$title = quotemeta(trim($video[2])) . ".mpg";
$basename = trim($video[1]);
if($cmd eq '-t'){
print "ln $basename xfer/$title \n";
print "rm $basename*\n";
}elsif($cmd eq '-l'){
`ln $basename xfer/$title`;
}elsif($cmd eq '-d'){
`rm $basename*`;
}elsif($cmd eq '-dd'){
push(@filenames, $basename);
}
}
if($cmd eq '-dd'){
print "delete from recorded where basename in (\n";
$first = 0;
foreach $file (@filenames){
print " " . ($first++?',':'') . "'$file'\n";
}
print ");\n";
}
# Perl trim function to remove whitespace from the start and end of the string
sub trim($) {
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
# Left trim function to remove leading whitespace
sub ltrim($) {
my $string = shift;
$string =~ s/^\s+//;
return $string;
}
# Right trim function to remove trailing whitespace
sub rtrim($) {
my $string = shift;
$string =~ s/\s+$//;
return $string;
}
sub useage{
print "The file ma contains a list of files from the following query\n";
print " select basename, title, filesize from recorded order by filesize, title;\n\n";
print "Create a folder called xfer\n\n";
print "-h for help\n";
print "-t test run (just print link statements\n";
print "-l create links\n";
print "-d delete original files\n";
print "-dd database delete command\n";
}
Sunday, November 15, 2009
Script to move mythtv files to another server
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment