Unrar and cleanup script - UPDATE 2013.05.24

Discussion of Transmission that doesn't fit in the other categories
ScheffK0ch
Posts: 2
Joined: Wed May 18, 2011 10:18 pm

Re: Unrar and cleanup script - UPDATE 2011.05.09

Post by ScheffK0ch »

Hi there,

thanks for the script, although I don't get it working ;)

I'm a linux newb, so please be kind :o)

My settings.json looks like:
...
"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/root/posttorrent.sh",
...

If I check the logfile, I don't get any entries, so Transmission doesn't even start the script after completion of a torrent.

Any idea why?

Thanks in advance,
ScheffK0ch
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.05.09

Post by killemov »

My first suggestion would be to set the permissions for the script file to full.
chmod 777 /root/posttorrent.sh

The way transmission works with the settings.json may also be confusing. Make sure transmission is not running when you edit the configuration file.
ScheffK0ch
Posts: 2
Joined: Wed May 18, 2011 10:18 pm

Re: Unrar and cleanup script - UPDATE 2011.05.09

Post by ScheffK0ch »

That did the trick !!!
Thank you killemov :o)
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.06.29

Post by killemov »

I have updated the start post with a new script.

I have implemented better handling of the current style of multi-archive rar files (.partXX.rar). It only unrars .part01.rar files and ignores .part02.rar and up because those files should be handled by unrar.
adambrug
Posts: 4
Joined: Fri Jul 29, 2011 12:12 pm

Re: Unrar and cleanup script - UPDATE 2011.06.29

Post by adambrug »

im having trouble running this fantastic script

im having a similar problem to another who posted here although in my case it doesn't appear the script is executing at all - i dont even see a log file being created?

Settings.json appears as:

"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/mnt/data/Torrents/extract.sh",

I have changed permission to 777 to 'extract.sh' and the download directory and i have edited the settings file while unmounted, what else am i missing here?

help!
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.06.29

Post by killemov »

While unmounted? You mean while transmission wasn't running? Stop and start transmission and verify your changes to settings.json are still there.
Oh, and double check the path/filename of the script again.
Is unrar on your system?
Have you properly modified the variables IN the script?
adambrug
Posts: 4
Joined: Fri Jul 29, 2011 12:12 pm

Re: Unrar and cleanup script - UPDATE 2011.06.29

Post by adambrug »

Sorry - by unmounted i mean transmission is not running, the settings are definitely being saved to the settings.json
path/filename are correct
unrar is installed and working

can you confirm exactly what needs to be modified in the script as I haven't touched any of it, this is where im probably going wrong.

thanks killemov

update: ive updated the script with username/password info at the beginning - i assume this is what i use to login to the transmission webgui?

the login details are correct as i can login to the transmission-remote from the command line, not sure if im on the right track here though?

still nothing extracts though and no log file being created (/var/log/posttorrent.log), its like the script its not even attempting to run?
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.06.29

Post by killemov »

Please insert after the two lines starting with #:
echo "start" >> /var/log/posttorrent.log

and have transmission finish a torrent again. (I use echo "" > somesmallfile, verify torrent and continue download.)

If there is no line "start" in the logfile then the script wasn't called from transmission OR you are not running the script in a bash environment. In either case I can't help you any further.
adambrug
Posts: 4
Joined: Fri Jul 29, 2011 12:12 pm

Re: Unrar and cleanup script - UPDATE 2011.06.29

Post by adambrug »

im not sure exactly what you mean by this
(I use echo "" > somesmallfile, verify torrent and continue download.)
i have added echo "start" >> /var/log/posttorrent.log to the beginning of script and still no log is being created which implies the script isnt even starting, im using Freenas. Running the simple echo command to a log file from the bash shell works no problem.

Would it be a permission issue? The script file and folder its contained in are all 777 and so is my downloads folder, user mask is set to 000 for downloads, am i missing else here? The path to the script is definitely correct in the settings.json, any other reason you might be aware of why the script would be prevented from running?

really appreciate your assistance with this. thanks again
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.06.29

Post by killemov »

Have you tried starting the script manually? ( bash yourscript.sh )
adambrug
Posts: 4
Joined: Fri Jul 29, 2011 12:12 pm

Re: Unrar and cleanup script - UPDATE 2011.06.29

Post by adambrug »

have run it manually (didnt realise this would work), the script runs as a log file is being created although getting the following:

2011-08-02 20:48:54 Error unrarring

i have a torrent rar'd sitting in my downloads folder at the time.

im not sure why the file isnt unraring, when i run the script manually do i need to specify anything further or just run the script as is?

i dont get this far if i specify the script in the settings.json as it doesnt appear to run at all in these cases

so frustrating :cry:
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.06.29

Post by killemov »

Ok, this suggests that the script is at least able to run on your system and that unrar is called. The problem still is that the script isn't called from transmission. If you have (triple!)checked for proper configuration of the settings.json file and the script is in the correct place with the correct name ("cat /mnt/data/Torrents/extract.sh" shows the content of the script), then I'm out of ideas.
dashy
Posts: 2
Joined: Thu Aug 18, 2011 5:21 pm

Re: Unrar and cleanup script - UPDATE 2011.06.29

Post by dashy »

Well, I am having some issues with this script. I have been able to get it to work 100% when I execute the script from terminal - "bash posttorrent.sh" will extract the .rar and if the variable torrent id is changed with a 1, it will delete the torrent as well. The log file also shows that it has been called.

Code: Select all

root@dlink-4C13E6:/mnt/HD/HD_a2/.transmission-daemon# ls -l
total 44
drwxr-xr-x 2 nobody allaccount  4096 Aug 18 05:12 blocklists
-rwxrwxrwx 1 nobody allaccount  2171 Aug 19 03:05 posttorrent.sh

Code: Select all

root@dlink-4C13E6:/mnt/HD/HD_a2/.transmission-daemon# cat posttorrent.sh
#! /bin/bash
# posttorrent.sh by Killemov
{
  # Log file, file where we tell what events have been processed.
  LOG_FILE=/mnt/HD/HD_b2/posttorrent.log
  # Username for transmission remote.
  TR_USERNAME="admin"
  # Password for transmission remote.
  TR_PASSWORD="*edited*"
  # 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}/"
  # This parameter string could be passed from Transmission in the future.
  TR_TORRENT_PARAMETER="EXTRACT SLEEP1h"

  if [ -e "$SRC_DIR/keep" ]; then
    TR_TORRENT_PARAMETER="$TR_TORRENT_PARAMETER KEEP"
  fi

  if [ -e "$SRC_DIR/exit" ]; then
    TR_TORRENT_PARAMETER="EXIT"
  fi

  # Actual processing starts here.
  if [[ "$TR_TORRENT_PARAMETER" =~ "EXIT" ]]; then
    echo $NOW "Exiting $TR_TORRENT_NAME" >> $LOG_FILE
    exit 0
  fi

  if [[ "$TR_TORRENT_PARAMETER" =~ "EXTRACT" ]]; then
    cd $TR_TORRENT_DIR
    if [ -d "$SRC_DIR" ]; then
      IFS=$'\n'
      unset RAR_FILES i
      for RAR_FILE in $( find "$SRC_DIR" -iname "*.rar" ); do
        if [[ $RAR_FILE =~ .*part...rar ]]; then
          if [[ $RAR_FILE =~ .*part01.rar ]]; then
            RAR_FILES[i++]=$RAR_FILE
          fi
        else
          RAR_FILES[i++]=$RAR_FILE
        fi
      done
      unset IFS

      if [ ${#RAR_FILES} -gt 0 ]; then
        for RAR_FILE in "${RAR_FILES[@]}"; do
          unrar x -inul "$RAR_FILE" "$DEST_DIR"
          if [ $? -gt 0 ]; then
            echo $NOW "Error unrarring $TR_TORRENT_NAME" >> $LOG_FILE
            exit 0
          fi
        done
        #if [[ ! "$TR_TORRENT_PARAMETER" =~ "KEEP" ]]; then
        #  SLEEP=$(expr match "$TR_TORRENT_PARAMETER" '.*SLEEP\([0-9a-zA-Z]*\)')
        #  if [ ${#SLEEP} -gt 0 ]; then
        #    sleep $SLEEP
        #  fi
        transmission-remote -n $TR_USERNAME:$TR_PASSWORD -t$TR_TORRENT_ID --remove-and-delete
        #fi
        echo $NOW "Unrarred $TR_TORRENT_NAME" >> $LOG_FILE
      fi
    fi
  fi
} &

Code: Select all

    "script-torrent-done-enabled": true,
    "script-torrent-done-filename": "/mnt/HD/HD_a2/.transmission-daemon/posttorrent.sh",

Code: Select all

[04:17:35.656] *edited* Calling script "/mnt/HD/HD_a2/.transmission-daemon/posttorrent.sh" (torrent.c:1909)
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.06.29

Post by killemov »

@dashy: Hmmm ... you've edited out the keep/sleep functionality, which is not unimportant. What are the actual problems with that segment of the script?
killemov
Posts: 542
Joined: Sat Jul 31, 2010 5:04 pm

Re: Unrar and cleanup script - UPDATE 2011.09.10

Post by killemov »

I have updated the start post with a new script.

I encountered a few .part1.rar torrents. Support for these is implemented ( as well as .part0001.rar ) so they are properly handled.
Post Reply