[Linux] Rename downloads as NZB

Come up with a useful post-processing script? Share it here!
Post Reply
Orbi
Newbie
Newbie
Posts: 16
Joined: February 26th, 2010, 3:34 am

[Linux] Rename downloads as NZB

Post by Orbi »

Hello,

I just wrote this simple script to cover my simple needs. What I would like is that the files I download are renamed as the NZB I download. Sabnzbd already puts these downloaded files in a directory named after the NZB.

Currently the situation is like this:

Movies/NZBnameinqueu/a.mkv
                                    b.nfo
                                    c.srt

I would like it to become this:
Movies/NZBnameinqueu/NZBnameinqueu.mkv
                                    NZBnameinqueu.nfo
                                    NZBnameinqueu.srt

Please bear with me as this is the first code I ever wrote (probably cannot get any simpler :P). Can the experts tell me if it will do what I would like it to do?

Code: Select all

#!/bin/bash
fullpath=$1
filename=$3
cd $fullpath
mv $* filename
Thanks!
sweetie
Full Member
Full Member
Posts: 117
Joined: May 10th, 2009, 10:47 am

Re: [Linux] Rename downloads as NZB

Post by sweetie »

That won't.

Code: Select all

#!/bin/bash

for files in *; do
  [ ! -f "$3.${files##*.}" ] && mv -v "$files" "$3.${files##*.}"
done
That will.
Of course if you have multiple files with same extension only the first will be renamed.
Orbi
Newbie
Newbie
Posts: 16
Joined: February 26th, 2010, 3:34 am

Re: [Linux] Rename downloads as NZB

Post by Orbi »

sweetie wrote: That won't.

Code: Select all

#!/bin/bash

for files in *; do
  [ ! -f "$3.${files##*.}" ] && mv -v "$files" "$3.${files##*.}"
done
That will.
Of course if you have multiple files with same extension only the first will be renamed.
Thanks for trying to help me out. Your script worked in an unexpected way. Instead of renaming the downloaded file, it renamed my entire SABnzbd program directory, making the application crash instantly. I was worried 2 seconds hoping my entire file server would not have been renamed. Luckily only did the Sabnzbd directory.

What happened?
sweetie
Full Member
Full Member
Posts: 117
Joined: May 10th, 2009, 10:47 am

Re: [Linux] Rename downloads as NZB

Post by sweetie »

Oh sorry. You'll need to change directory to download dir. (You had that part right in your psuedo-script.)

Code: Select all

#!/bin/bash

cd "$1"

for files in *; do
  [ ! -f "$3.${files##*.}" ] && mv -v "$files" "$3.${files##*.}"
done


Note: Strongly recommend always running scripts in a test folder before a critical/live environment, though in this case it was my fault, sorry!
Orbi
Newbie
Newbie
Posts: 16
Joined: February 26th, 2010, 3:34 am

Re: [Linux] Rename downloads as NZB

Post by Orbi »

That does exactly what I wanted! Now I have Sabnzbd fully configured, everything is automated. I love it.

And thanks for complimenting my pseudo-scripting abilities  ;D
Post Reply