Page 2 of 3

Re: simple script to move files after processing

Posted: February 10th, 2011, 1:55 pm
by CloudDweller
Thanks Mar2zz for the script.  I have to admit I'm a total noob and must be doing something wrong as I can't get it working.  Where exactly am I supposed to enter the location of the output folder?  The script log just says request unsuccessful.  I'm not at all familiar with scripting and really need hand holding.  Thanks for your patients.

Re: simple script to move files after processing

Posted: February 10th, 2011, 2:10 pm
by Mar2zz
Please post your log so I can see what to edit, you can find the log in history of sabnzbd, click the + sign and then more, copy that content and paste it here or on pastebin.com and link it here.

The outputpath is virtually created (or guessed) with this: sed "s#/Users/Chris/Downloads/#/Network Drive/#g")

/Users/Chris/Downloads/ is replaced by /Network Drive/, so you need to edit /Network Drive/ I suppose to your networkdrivename and rootfolder (rootfolder is the folder where your TV and Movies share are in) For example: \\Linkstation\
So try: sed "s#/Users/Chris/Downloads/#smb://Linkstation/#g") or see below. The best option is to mount your linkstation locally.

This virtual replacing mirrors the exact situation of folders and files inside /Users/Chris/Downloads/ to \\Linkstation\. This way it will see for itself if the prefix is Movies or TV (or other categories for that matter, if you create special folders for it on your desktop it will mirror them on your NAS.)

Ah wait, those networkadresses are irritating, they need escaping as \ is an escape itself. Did you mount it? else you need to escape it and change all / to \.
Use the mounted networkdir by preference, else use two pipes, replace the newpath by this

Code: Select all

newpath=$(echo $folders | sed "s#/Users/Chris/Downloads/#//Linkstation/#g" | sed "s#/#\\#g")

Re: simple script to move files after processing

Posted: February 10th, 2011, 2:44 pm
by CloudDweller
Here is my log file without anything changed from the script you gave me.

http://pastebin.com/raw.php?i=Y4LhM5te

Hopefully you can see what the problem is as your last post about "escapes" and "pipes" totally lost me  :-[  Also, I might be misunderstanding what your script does, but I've worked out that my network drive address is "/Volumes/TV or /Volumes/Movies" so could I not enter these locations instead of virtually creating/guessing it.  Like I said, I may be totally misunderstand what you're doing.

Re: simple script to move files after processing

Posted: February 10th, 2011, 3:46 pm
by Mar2zz
I am sorry, I will not be to technical. Yes you need pathguessing, why? Otherwise the script can't see which path a tvshow has to go in. We need the last part of your folder behind /Users/Chris/downloads/.  This part we need: TV/The Big Bang Theory/Season 3/ is the part we need to store your shows in the right location. Replacing with sed does that for you.

Now, we need to replace /Users/Chris/downloads/ with /Volumes/. You want /Users/Chris/downloads/TV/The Big Bang Theory/Season 3/The Big Bang Theory - S03E14.avi to go to /Volumes/TV/The Big Bang Theory/Season 3/The Big Bang Theory - S03E14.avi right?

I don't know for a Mac, but Linux is very casesensitive when it comes to file and foldernames.

Your downloadfolder isn't Downloads but downloads. In bash always watch for these little mistakes.
Here is the script you need:

Code: Select all

#!/bin/bash

# VARIABLES 
#---- EDIT HERE IF THINGS CHANGE, E.G. OTHER NETWORKLOCATION----

local="/Users/Chris/downloads/";
network="/Volumes/";

#---- DO NOT EDIT BELOW -----

for folders in $1 #### for all folders inside the downloadpath do the following
do
newpath=$(echo $folders | sed "s#$local#$network#g") #### create new path by replacing local dirs with networkdir
mkdir -p "$newpath" || #### make the newdir if it doesn't exist
mv -f "$folders/*.*" "$newpath"
#rm -Rf $1 #### uncomment to delete sourcefolder.
done

note: you can do testruns by executing the script like this ./scriptname "/path/to/process" e.g. /.movefiles "/Users/Chris/downloads/TV/The Big Bang Theory/Season 3/". The part behind the scriptname is $1. So you don't need to download everytime to test ;)

Re: simple script to move files after processing

Posted: February 10th, 2011, 5:55 pm
by CloudDweller
Thanks for the new script.  I ran it but it still didn't move any files  :(  I then removed the forward slashes at the end of the local and network location and this is what I am now getting.

Download Folder:
Users/Chris/downloads/TV/Legend of the Seeker/Season 2/video file.mkv

Network Drive:
Volumes/TV/Legend/

So its starting to create a folder structure on my network drive but the show name folder's name isn't complete and there's nothing inside it.

P.S. I'm not actually downloading a TV show, just a sync fix but this shouldn't cause a problem should it?

Here is a copy of my latest log if this helps http://pastebin.com/raw.php?i=ZR2LVU3K

Re: simple script to move files after processing

Posted: February 11th, 2011, 1:03 am
by Mar2zz
Your pastebin link doesn't work
Then it works, but is missing quotationmarks somewhere. I always forget those... spaces in locations break up scripts if it is not properly quoted...

Here, I quoted everything to be sure.

Code: Select all

#!/bin/bash

# VARIABLES 
#---- EDIT HERE IF THINGS CHANGE, E.G. OTHER NETWORKLOCATION----

local="/Users/Chris/downloads/";
network="/Volumes/";

#---- DO NOT EDIT BELOW -----

for folders in "$1" #### for all folders inside the downloadpath do the following
do
newpath=$(echo "$folders" | sed "s#$local#$network#g") #### create new path by replacing local dirs with networkdir
mkdir -p "$newpath" || #### make the newdir if it doesn't exist
mv -f "$folders/*.*" "$newpath"
#rm -Rf "$1" #### uncomment to delete sourcefolder.
done

Re: simple script to move files after processing

Posted: February 11th, 2011, 2:47 pm
by CloudDweller
Okay I think we are nearly there. The directory structure is being created but the final file (avi, mkv, iso etc...) isn't being copied/moved.  I'm at work at the moment so will send you my log file when I'm home.  Thanks again for all your help.

Re: simple script to move files after processing

Posted: February 12th, 2011, 2:53 am
by Mar2zz
Ok, I learned some shortcomings in the mv-command. It can't move directory's to directory's that allready exist. That's kinda stupid in my opinion. So I did some research and we need the copycommand. After the copy te source can be deleted, and so it is the same as the move-command but with more options.

Also || works a little different then I thought it would. I still need to learn a lot about bash, I write bashscripts for a month now, I can be considered a noob too, so this one was a nice study...  ;) (Let's hope it's fixed now or I'll have to study some more). First test it, and if it works remove # from this one: #rm -Rf "$folders", that one will throw away the source after it's copyied to your networklocation.

I edit the code below the variables:

Code: Select all

for folders in "$1" #### for all folders inside the downloadpath do the following
do
newpath=$(echo "$folders" | sed "s#$local#$network#g") #### create new path by replacing local dirs with networkdir
mkdir -p "$newpath" #### make the newdir if it doesn't exist
cp -TRf "$folders" "$newpath"  #### copy all files and folders inside the downloadpath 
#rm -Rf "$folders" #### delete sourcefolder
done

Re: simple script to move files after processing

Posted: February 14th, 2011, 6:09 pm
by CloudDweller
Sorry I meant to post a couple of days ago but I haven't been able to test the last script until today. It works great. Thank you so much for all your help with this. I really do appreciate it ;D

Re: simple script to move files after processing

Posted: February 28th, 2011, 4:59 am
by Adamward
I was looking for this coding , I am  going to give it a try now.

Re: simple script to move files after processing

Posted: March 1st, 2011, 11:10 am
by CloudDweller
Is there a way to confirm that the files have been moved prior to deletion?  At the moment, if the ‘mv’ command tries to move the files and fails it will still run the ‘rm’ command and delete the files.  I’d prefer it to check first and if the move has failed then it doesn’t remove the files, if it has worked then it does.

Is this possible?

Re: simple script to move files after processing

Posted: March 1st, 2011, 12:57 pm
by Mar2zz
Just add && behind the cp command, this means after command is succesfull go to the next command, else it stops.
cp -TRf "$folders" "$newpath" &&
rm -Rf "$folders"

Re: simple script to move files after processing

Posted: March 25th, 2011, 6:10 pm
by mfacer
racso wrote: I currently use this script on a OSX Mac.

Code: Select all

#!/bin/bash

if [ "$5" = "movies" ]; then
  mv -fv "$1" "/Volumes/External HD/Media/Movies"
elif [ "$5" = "tv" ]; then
  mv -fv "$1" "/Volumes/External HD/Media/TV"
fi
Note that you can change the "/Volume/../.././" bit to whatever you like. Even (mounted) network drives!

If you want to see your mounted disks go to the "Finder" menu -> "Go" -> "Go to folder". Then type "/Volumes/" (without the quotes) and voila!  
Hey - I'm now running sabnzbd on my mac mini... I tried the above script (working on my Amahi box) but I cannot for the life of me get it to work! I get the message "Exit(-1) Cannot run script /Users/matt/downloads/sort2.sh". I've CHMOD to 777 and tried moving it around. I have tried cutting down the script to just work on the one folder and all sorts. What were the settings for Mac OSX you used? I'm running this on an old mac mini (Tiger 10.4)

Thanks

Re: simple script to move files after processing

Posted: March 26th, 2011, 1:15 pm
by Mar2zz
That's probably a problem with line endings (invisible stuff). See http://en.wikipedia.org/wiki/Line_endings

Convert it to LF for Mac I think.

Re: simple script to move files after processing

Posted: April 10th, 2011, 8:19 pm
by Crush
I am looking for a script similar to this. What I want is for the contents of the final folder (that is, after unpacking) to be moved to my desktop. I have tried this:

Code: Select all

mv -fv "$1/*" ${HOME}/Desktop/
but I get an error saying
mv: rename /Users/[REDACTED]/Desktop/Test/* to Desktop/*: No such file or directory