Monitor Folder For New SubFolder / Execute Script Or Cron Job

Status
Not open for further replies.

Mirfster

Doesn't know what he's talking about
Joined
Oct 2, 2015
Messages
3,215
Sorry if this was already answered elsewhere (was having no luck with search results urls working this morning)

I'm testing out setting quotas on User Home Directories and figure that I can easily set them with something like:
Code:
zfs set userquota@"Domain\User"=50G Data/Users

Only thing is that I am not making a User's Home folder the normal way. While there will be a DataStore and Share for "Users"; it is simply a Folder created via Windows Explorer that I will set the initial rights on (FreeNAS is also the Domain Controller here).

Rights aside, I could simply putty into FreeNAS and execute the command personally. But, I will not be the only person administering this and would prefer more of an automated method.

So, is there a simple way of monitoring "Data\Users" for a new SubFolder (only 1 level deep mind you) and execute a script (perhaps something like 'OnEvent' even)?
  • I know that I could simply setup a Cron Job to run often, but wanted a more intelligent solution
  • Wanting this to reside on FreeNAS itself and not another box (like Windows with a PowerShell Script)
Thanks in advance and if I am overlooking a simple solution, please feel free to hit me over the head with a keyboard. :)

P.S. Running FreeNAS 9.10
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Perhaps you can look at the devel/libinotify port/pkg to see how you would use it to get notified of changes to files/dirs. https://www.freshports.org/devel/libinotify

I also noticed there's a freebsd daemon available on github https://github.com/faelys/filewatcherd that seems to claim to be what you're asking for... I'm not 100% clear if it can watch for dirs alone or if it can only watch for files, but seems like what you want if you can rely on a file being there (or if you're better than me at reading the instructions, for empty dirs).
 

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703

Mirfster

Doesn't know what he's talking about
Joined
Oct 2, 2015
Messages
3,215

sretalla

Powered by Neutrality
Moderator
Joined
Jan 1, 2016
Messages
9,703
Well, you would install it in a jail, so not really invasive in that sense...

I see that the work is all based on kqueue/kevent native functionality, but I suspect those are harder to use directly, hence the additional tools.
 

Arwen

MVP
Joined
May 17, 2014
Messages
3,611
I too wanted something that triggered a FreeNAS command. In my case, when my Rsync backups are done, I snapshot the backup dataset on my NAS with the current date. That way, each individual backup only takes as much space as what changed. A poor elf's de-duplication, since it does not span clients which may have the same exact files.

At present it's a manual step after my backups. But, I guess I will write a cron job to do the work...
 

Mirfster

Doesn't know what he's talking about
Joined
Oct 2, 2015
Messages
3,215
I am pondering the idea of simply automating the creation of a file named something weird (like "OkayTimeToDoThatCronJob"); then have a cron job that runs every X minutes to look for that file. If it that file exists then it will do what I want and delete the file initially created...

Not my best idea but leaning towards that for now.
 

Arwen

MVP
Joined
May 17, 2014
Messages
3,611
I am pondering the idea of simply automating the creation of a file named something weird (like "OkayTimeToDoThatCronJob"); then have a cron job that runs every X minutes to look for that file. If it that file exists then it will do what I want and delete the file initially created...

Not my best idea but leaning towards that for now.
Basically what I will probahly do.

Don't forget to remove the file "OkayTimeToDoThatCronJob" at the beginning of the cronjob. If the task takes longer than the cronjob interval, (like 1 minute), then another instance of the task will be launched if the file still exists. As a former professional programmer, that's something I think of, (fault tolerance).
 
Status
Not open for further replies.
Top