0

I'm sorry that I can't be extremely specific, I really don't know what is the problem and just started with bash so my debugging skills are limited to echo.

I have the following piece of code:

#! /bin/bash
# post_torrent.sh
{
  # Log file, file where we tell what events have been processed.
  LOG_FILE=/Users/Server/Documents/sickbeard/logs/post_torrent.log
  # Username for transmission remote.
  TR_USERNAME="admin"
  # Password for transmission remote.
  TR_PASSWORD="1234"
  # Get current time.
  NOW=$(date +%Y-%m-%d\ %H:%M:%S)
  # Source directory, should not be changed.
  SRC_DIR="${TR_TORRENT_DIR}/${TR_TORRENT_NAME}/"
  # Directory to store the un-compressed files in..
  DEST_DIR="${TR_TORRENT_DIR}/${TR_TORRENT_NAME}/"

    cd $SRC_DIR
    echo $NOW "SRC_DIR $SRC_DIR" >> $LOG_FILE
    RAR=$(find . -iname "*.rar")
    echo $NOW "RAR $RAR" >> $LOG_FILE
    unrar x -inul "$RAR"

    exit 0
} &

The log file shows that the correct files are being used. When i execute the statements in the script one by one in the terminal (I am working on a mac osx server) everything works and the file gets extracted. However when this script is executed after a torrent has been downloaded it does not.

I have been trying to find out why this is for about three hours and still have not found any clue. I think the permissions are OK as I tested for that. I am however new to bash and not too familiar with the mac osx command line.

Thanks in advance.

EDIT: some extra information. the log looks like this: 2013-02-27 00:14:42 SRC_DIR /Volumes/Multimedia/aa_bb/Downloads/some_serie/ 2013-02-27 00:14:42 RAR ./some_serie.rar

The program gets executed through transmission as the program set when a file finishes downloading.

The file that has to be extracted is on a shared external hard drive.

Hope this helps.

Boelensman1
  • 314
  • 2
  • 15
  • Dont you need to unrar them in order, in a serial fashion - meaning 1, then 2, then 3, etc..? If so ithink the problem is that youre trying to unrar them potentially in paralell... Could be worng though. Simple solution is to avoid RAR archive torrents. Ive been on a crusade against them for years now :-) – prodigitalson Feb 26 '13 at 22:03
  • Make new script and add content line by line testing it with output to terminal. Maybe there is some problem with your particular file (in settings, etc...). So create new script with functions you need to use and execute try to execute it. – Stepo Feb 26 '13 at 22:04
  • It seems likely that RAR contains more than one file name, but when you pass it to unrar like this: `unrar x -inul "$RAR"`, unrar will see all of them together as one argument. You might try removing the quotes from around the variable. (It gets trickier if your file names might contain spaces.) – William Feb 26 '13 at 22:05
  • Add `set -x` to the beginning of the script for debugging. – user000001 Feb 26 '13 at 22:05
  • @user000001 What does set-x do? – Boelensman1 Feb 26 '13 at 23:12
  • Try it. It prints every command before it executes, so you can see your errors. – user000001 Feb 26 '13 at 23:14
  • @user000001 Thanks. Do you also happen to know how i can write that output to a file? It still does not work when executed by the torrent client, and naturally I don't have a console then. – Boelensman1 Feb 26 '13 at 23:41
  • @Boelensman1 Add `exec 2>mylog` after set `set -x`, so that you redirect the standard error to the `mylog` file. And you need a space after set ` – user000001 Feb 26 '13 at 23:46

1 Answers1

1

change the line :

unrar x -inul "$RAR"

to :

for i in $RAR 
do
   unrar -x inul $i
done

the reason for this is that $RAR contains all the results and you want to parse each result individually

[edit]
I note that you haven't shown the above changes in your example - what you want to do won't work without them

change this line :

RAR=$(find . -iname "*.rar")

to:

RAR=`find . -iname "*.rar"`

Those are quotes by the way, they're grave accents
add the output of the set -x to your question
[/edit]

KevinDTimm
  • 14,226
  • 3
  • 42
  • 60