Is there a way to watch a folder and move files based on rules?

Status
Not open for further replies.

Ray Milyard

Patron
Joined
Aug 8, 2014
Messages
262
I have 2 pools. tank and tank2. I use tank for my downloading media and storing my tv shows and normal movies. On tank2 I like to keep all my true blu rays and 3d blu rays in .iso format.

Tank has sabnzbd, couchpotato, sickrage and transmission. Right now all the files download in either tank/mnt/media/videos either /tvshows or /movies.

I would like someway to watch the movies folder and if finds a file type .iso or name with name .3d to move them to tank2/mnt/media2/movies/blu rays

If anyone can help me and let me know if can be done that would be GREAT!
 

Ray Milyard

Patron
Joined
Aug 8, 2014
Messages
262
It has nothing to do with freenas at that point. Any tutorial on creating a script to move specific files will work.

To be honest I have kinda looked but not know much about scripting and FreeBSD not sure how to go about this.

Since going from one volume to another can I do this? The files will be from time to time 50gb plus in size.
 

Ray Milyard

Patron
Joined
Aug 8, 2014
Messages
262
To be honest I am not sure how I can and if can do this.

I want to watch the folder /mnt/tank/media/videos/movies. Inside this folder I have my movies names in folder of the movies. IE: American Ultra (2015). Then inside the movie name folder I have files like:

American Ultra (2015).iso
American Ultra (2015).nfo

I would like to watch for file types nested inside /mnt/tank/media/videos/movies that have the .iso. If finds them then copy the American Ultra (2015) folder and contents inside to /mnt/tank2/media/movies/blu rays

I hope this all makes sense.

Also if works then maybe one step further. If the file name contains .3D in the name then move it to /mnt/tank2/media/movies/3D blu rays.
 

pirateghost

Unintelligible Geek
Joined
Feb 29, 2012
Messages
4,219
It is absolutely doable, but ignore 'watching a folder' and instead 'find files w/<uniqueidentifier>' and set it up as a cron task. I do a simple rsync to copy .iso files from one dataset to another that runs every hour. Your script will be a little more in depth, but it is possible to do so.

I have not given you the exact syntax here because I think this is something you would benefit from looking up yourself and learning from.

'find' is a great command and very powerful. please research 'freebsd find command', 'find command', or 'freebsd find command script'
 

Ray Milyard

Patron
Joined
Aug 8, 2014
Messages
262
So digging around I found I can use this to FINE the files with name of 3d.iso with

fine /mnt/tank/media/videos/movies -name "*.3d.iso"

Now since can find them not sure what else should be doing to try the rsync etc together.
 

Ray Milyard

Patron
Joined
Aug 8, 2014
Messages
262
The command is 'find'

http://www.freebsd.org/cgi/man.cgi?find(1)

Just look at the examples. You could use mv instead of rsync and it would achieve the same effect

So a friend and I messed with this for hours today. We can move the file. IE: Ant-Man (2015).3D.iso without any issues. We can't seem to find how to make it move the folder that contains the file. In this case would be Ant-Man (2015). Would like to find the files with .3D in the name but move the whole directory to new drive.
 

Ray Milyard

Patron
Joined
Aug 8, 2014
Messages
262
Still having no luck with this. I can only get the .iso file to copy and not folder that contains the file.
 

Neil Whitworth

Dabbler
Joined
Nov 14, 2013
Messages
30
A combination of cron (to schedule) and shell script with rsync (to copy) should do what you want.

Rsync has 2 options that can control what is synced. --include & --exclude (see man page for details). Using both togeather can be tricky, but if you can stick to just an include (or just an exclude) patten you should be fine.

here is something to get you started...

Code:
#!/bin/sh

SRCDIR=/mnt/tank/downloads/TV
DESTDIR=/mnt/tank/Media/Videos/Series

rsync --dry-run -av --progress "${SRCDIR}" "${DESTDIR}" --exclude '*.part'
 
Status
Not open for further replies.
Top