Setting up a watch folder under Linux

General questions regarding Linux.

Moderators: Terry, FWLUG Administrator

Setting up a watch folder under Linux

Postby erroneus » Wed Jan 14, 2009 5:03 pm

This is definitely something I could cobble together on my own but I have decided to pose the question here because the answers might be more generally educational and because the answers might be better than anything I would have considered.

Here's the project:

Users on a small network (3 users total) are using an SME server to host their files, their logins and that sort of thing. They also print through this server. They have an HP600 plotter at their site as well.

Recently, for whatever reason, their ability to send plot files to their plotter has broken. Probably some Windows update has thrown a monkey-wrench into the works, but I don't care to fix Windows problems and it occurred to me that all we need to do is set up a watch folder and let people drag and drop their plot files into the folder and let the server do the job of queuing the file and spooling to the plotter.

I have already successfully sent a plot file to the plotter from command line, so that functionality is simple and works. So now I just want to set up a "watch folder" that will respond to plot files being present by sending them to the plotter and then deleting the file.

I imagine setting up a cron job to run every minute and when it sees a file in the folder, it would launch a script that does the work.

How would "you" do it? I like bash scripting, but perl would be fine... or frankly, whatever you like best.

This is the sort of process that could be adapted for all sorts of tasks such as image processing or anything else you would like to let a server handle in response to a file being copied to a folder.
User avatar
erroneus
 
Posts: 49
Joined: Tue Feb 27, 2007 4:18 pm

Re: Setting up a watch folder under Linux

Postby Insanity5902 » Thu Jan 15, 2009 9:59 am

http://www.gnome.org/~veillard/gamin/

Uses kernel inotify, provides and api, most "full blown" products use this.

You could write bash script to print all files in a directory and then delete them when sent to the print queue. That would be the quick hack. Using gamin would probably be considered a more elegant solution.
Insanity5902
 
Posts: 41
Joined: Tue May 13, 2008 8:49 am

Re: Setting up a watch folder under Linux

Postby erroneus » Thu Jan 15, 2009 10:39 am

Yeah, not available to SME server... not just yet. Will be available in SME when released. (Beta 3 is out though)
User avatar
erroneus
 
Posts: 49
Joined: Tue Feb 27, 2007 4:18 pm

Re: Setting up a watch folder under Linux

Postby stack » Wed Jan 21, 2009 9:15 am

Take a look at incron.
http://www.linux.com/feature/144666

I think this might help.

~Stack~
User avatar
stack
 
Posts: 268
Joined: Sat Jul 14, 2007 2:11 pm
Location: Fort Worth, Texas

Re: Setting up a watch folder under Linux

Postby erroneus » Wed Jan 21, 2009 9:36 am

That would be awesome if it were available for SME 7.x. incron relies on inotify. inotify relies on a more recent kernel. SME 7.x is based on CentOS 4.x which uses a much older kernel -- 2.6.9 to be exact at the moment. I am unaware of any backports going back that far and replacing the kernel would likely be more work than it is worth as SME 8 would likely be released before I complete the task.
User avatar
erroneus
 
Posts: 49
Joined: Tue Feb 27, 2007 4:18 pm

Re: Setting up a watch folder under Linux

Postby stack » Thu Jan 29, 2009 4:22 pm

So I stumbled upon this article: http://www.linux.com/feature/150200

At first I was all giddy that I might have found another solution to your problem. Sadly the second sentence starts out:
Because fsniper uses inotify to monitor its directories..


Drats!

Anyway, it looks like fsniper is easier to setup and script so thought I would at least post back for anyone else who might need to use these features down the road.

~Stack~
User avatar
stack
 
Posts: 268
Joined: Sat Jul 14, 2007 2:11 pm
Location: Fort Worth, Texas

Re: Setting up a watch folder under Linux

Postby erroneus » Thu Jan 29, 2009 4:29 pm

So I will write a shell script that does an "ls -1" command and then parse through the files... the script will run every 60 seconds... I wonder how I can turn off the cron-log messages?

Another option is to run the script as a task forked from rc.local or run as a service in /etc/init.d and just have it "sleep" for 60 seconds between polling.
User avatar
erroneus
 
Posts: 49
Joined: Tue Feb 27, 2007 4:18 pm


Return to FWLUG General Discussions

Who is online

Users browsing this forum: No registered users and 16 guests

cron