MLDonkey Forum Index
Homepage •  Bugs •  Tasks •  Patches •  SF.net Project Page •  ChangeLog •  German forum •  Links •  Wiki •  Downloads
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
[SOLVED] Help in set script on File_completed_cmd

 
Post new topic   Reply to topic    MLDonkey Forum Index -> Alternative platforms
View previous topic :: View next topic  
Author Message
exente
neophyte


Joined: 14 Feb 2012
Posts: 1

PostPosted: Tue Feb 14, 2012 10:04 pm    Post subject: [SOLVED] Help in set script on File_completed_cmd Reply with quote

Hi All!

I'm sorry for start my first post with a question, but after i was several read Wiki and Forum, i can't find any solution to my question

I have a QNAP T419P II Nas with an unknow Linux distribution, on this, I have installed from qpkg package Mldonkey 3.1. At this point all works fine.

Reading Wiki, I can configure several options on Mldonkey, but I have found a problem with one question about File_completed_cmd option.

I try to set up a perl script that it's on thw Wiki (I paste bellow), but I can't execute it neither i find any error during it's execution.

Script consist on move downloads according to it's filename extension to especific folder.

I try to run other more basics scripts and it's work properly (I paste one of them below too)

mldonkey runs as root, and it's not need any environment modifcation. I have perl installed too and it's working fine on other services.

This is the script that doesn't work:
Code:


#!/opt/bin/perl
use strict;
use File::Basename;

# file_completed_cmd interface
my ($hash, $size, $file) = @ARGV;
exit if !$hash || !$size || !$file;

my $incoming='/share/Download/mldonkey/incoming/files';
my $minfreekb=1024;

# Define extensions here !!!

my %dispatch = (
# video series
   '.avi' => '/share/Download/mldonkey/incoming/Series/',
# video general
   '.mpg .mpeg .wmv .divx' => '/share/Download/mldonkey/incoming/Video/',
# image
   '.iso .bin .cue .img' => '/share/Download/mldonkey/incoming/',
# soft
   '.rar .exe .gz .msi .tar .tgz .zip' => '/share/Download/mldonkey/incoming/Software',
# audio
   '.mp3 .wma .ogg .mod .mp4' => '/share/Download/mldonkey/incoming/Musica/',
);

my $sizekb=($size+1023)/1024;
my $requiredkb=$sizekb+$minfreekb;

sub enough_space {
    my ($dir) = @_;
    my $dirfreekb = -1;
    if(open(DF, "df -k $dir|")) {
      my $headers = <DF>;
      my $line = <DF>; chomp $line;
      close DF;
      $dirfreekb = ( split(/[[ \t]]+/, $line) )[[3]] if defined $line;
    }
    $dirfreekb >= $requiredkb;
}

sub move_if_ok {
    my ($file, $dir) = @_;
    enough_space($dir) && system ('mv', $file, $dir)
}

my $ext = (fileparse($file, '\.[[^.]]+$'))[[2]];
while(my ($exts, $extdir) = each %dispatch) {
  my @exts = split / +/, $exts;
  if((grep { $_ eq $ext } @exts) > 0) {
    move_if_ok($incoming.$file, $extdir) && last
  }
}


This is the script that works fine as example:
Code:

#!/bin/bash
# file_completed_cmd interface
HASH="$1"
SIZE="$2"
FILENAME="$3"
echo "$1 $2 $3" > /share/Download/mldonkey/hello.txt


Anyone have any idea or probe that i can test? first of all, I have said that i don't have much ideo on perl...

Thanks in advance!!

King Regards

__________________________________________________________________________________________________________________________

Finally I can did it using bash as script in order to perl, I paste code below for if someone can help in the future.



Code:
#!/bin/bash

EXTENSION=$(echo "$1" | awk -F . '{print $NF}')


case "$EXTENSION" in
  txt)
    TARGETDIR=/mypath/for/text/files
    ;;
  avi)
    TARGETDIR=/mypath/for/video/files
    ;;
  *)
    TARGETDIR=/mypath/for/allother/files
    ;;
esac

mv $1 $TARGETDIR
exit 0


Best Regards
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    MLDonkey Forum Index -> Alternative platforms All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Sourceforge.net Logo