Help with User Script to copy job to another server and then move local copy

Come up with a useful post-processing script? Share it here!
Post Reply
User avatar
jackmetal
Newbie
Newbie
Posts: 6
Joined: November 11th, 2009, 2:07 pm

Help with User Script to copy job to another server and then move local copy

Post by jackmetal »

I have a short script that runs after my TV jobs: to move the show to my 'viewing' server, then move the local copy to a local 'backup' directory (just to keep a backup in case something happens).  I'm having a little problem figuring out the move portion, as  it won't move the directory if a directory with the same name already exists (the typical way *nix mv command works).

Here's the short script:

Code: Select all

#!/bin/sh
#
# SABnzbd Post Processing for TV downloads
#

# Copy downloaded TV to ViewingSys:/Videos/TV
scp -Bqr /Downloads/Complete/TV/* ViewingSys:/Videos/TV

# Move downloaded TV to local TV backup dir
mv -f /Downloads/Complete/TV/* /Backup/TV
I "think" I might be able to change the copy portion to:

Code: Select all

scp -Bqr $1 ViewingSys:/Videos/TV
Will that work?

Now, the portion I'm having issues with.  The mv portion works perfect, unless there is already a directory with the same name in the backup dir.  I thought about using "cp -r" and then "rm -r" on the directory, but of course I want to be completely sure of what I'm doing my "rm -r" on.  ;-)

If I understand correctly (and the $1 works as I mention about changing in my above "copy" portion of the script), I should be able to just change the "mv" command to something like:

Code: Select all

cp -r $1 /Backup/TV
rm -r $1
-or-  instead of the rm -r option, maybe a little 'safer' option would be as follows:

Code: Select all

rsync -a --remove-source-files --whole-file $1 /Backup/TV
rmdir $1
Does that look correct to the SABnzbd user script guru's?

--edit--
Well, I tried the option of changing my hard coded directory to $1 and it didn't work.. I've changed my script back to the directory and it's working great now.  I decided to go the route of rsync and rm -r /directory/* - and it 'seems' to be working fine now.  :-)  Though...if anyone has any suggestions as to a better way of doing it, it would definitely be appreciated!

Thanks!!
Last edited by jackmetal on November 15th, 2009, 6:25 am, edited 1 time in total.
Post Reply