Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Monitor a Dir for Changes?? then Run a script...?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
La`res
Arch/Herd Tester
Arch/Herd Tester


Joined: 11 Aug 2003
Posts: 79
Location: ::0

PostPosted: Fri Dec 12, 2003 9:55 pm    Post subject: Monitor a Dir for Changes?? then Run a script...? Reply with quote

I have looked back in the forums and found FAM and other threads relating to it. All to no avail. Now my Question is,

How do I have a script run when a Dir is changed?
IE. when a dir has pics put in it, run a script to make a thumb and add it to my website. I know how to write the script, I just need to know how to get it to run automatically. :D
_________________
Lares Moreau <lares.moreau@gmail.com>
LRU: 400755 http://counter.li.org
lares/irc.freenode.net
Back to top
View user's profile Send private message
slestak
Tux's lil' helper
Tux's lil' helper


Joined: 13 Jun 2003
Posts: 115

PostPosted: Sat Dec 13, 2003 12:07 am    Post subject: Reply with quote

I dont have the link, may have the Linux Journal mag around here, but they described a way to use Samba sppols as a way to operate on a set of files when they arrive in the dir.

I t was meant for printing, but they gave an example in the mag to show how to send files to a CDR by just copying them to the dir being watched.

I googled and found a howto http://www.linuxgazette.com/issue72/bright.html, I bet this technique could be adapted.
Back to top
View user's profile Send private message
ogre2112
n00b
n00b


Joined: 30 Nov 2003
Posts: 60
Location: East Coast, USA

PostPosted: Sat Dec 13, 2003 2:17 am    Post subject: Reply with quote

Would a cron job work?

Every x amount of time, run a script. The script takes any file in the directory, moves it to somewhere, and makes a thumbnail. Etc.
_________________
(= I smile because I have no idea what's going on =)
Back to top
View user's profile Send private message
nonotme
Guru
Guru


Joined: 29 Sep 2003
Posts: 356
Location: on.ca

PostPosted: Sat Dec 13, 2003 2:36 am    Post subject: Reply with quote

ogre2112 wrote:
Would a cron job work?

Every x amount of time, run a script. The script takes any file in the directory, moves it to somewhere, and makes a thumbnail. Etc.

you could write a makefile that's processed every x amount of time, only perform actions for changed files. from http://www.gnu.org/software/make/make.html:
Quote:
# Make is not limited to building a package. You can also use Make to control installing or deinstalling a package, generate tags tables for it, or anything else you want to do often enough to make it worth while writing down how to do it.

i've never done this, but it's a thought.[/code]
Back to top
View user's profile Send private message
maddog722
n00b
n00b


Joined: 22 Sep 2003
Posts: 24

PostPosted: Sat Dec 13, 2003 4:24 am    Post subject: Reply with quote

Yeah, a cron job is probably the easiest. Use something like:

find ./ -mmin -5 -exec ./myscript.sh {} \;

to find all the files modified within the last five minutes and execute the script on each, then set the cron job to run every five minutes or whatever.

Of course, you could also whip something up in C with fcntl and F_NOTIFY. See man fcntl for details.
Back to top
View user's profile Send private message
nempo
Guru
Guru


Joined: 16 Apr 2002
Posts: 360
Location: Linkoping, Sweden

PostPosted: Sat Dec 13, 2003 10:39 am    Post subject: Re: Monitor a Dir for Changes?? then Run a script...? Reply with quote

La`res wrote:
I have looked back in the forums and found FAM and other threads relating to it. All to no avail. Now my Question is,

How do I have a script run when a Dir is changed?
IE. when a dir has pics put in it, run a script to make a thumb and add it to my website. I know how to write the script, I just need to know how to get it to run automatically. :D


I've written a similar thing in perl. I did it so that every time someone visits my gallery the script is executed, it takes a look in the picture folder, and then looks for a matching thumbnail in the thumbs folder. If the thumbnail dosn't exist it creates one, if it does exist, the script just shows the thumb in the gallery.

This script also generates the html file so I don't have to go in and add the <img> tag.
_________________
homeobocks wrote:
superjaded wrote:

would Big Brother become a reality?

Yeah . . . it would be just like the tv show. Except somebody would be watching.
Back to top
View user's profile Send private message
La`res
Arch/Herd Tester
Arch/Herd Tester


Joined: 11 Aug 2003
Posts: 79
Location: ::0

PostPosted: Sun Dec 14, 2003 10:21 am    Post subject: Re: Monitor a Dir for Changes?? then Run a script...? Reply with quote

nempo wrote:

I've written a similar thing in perl. I did it so that every time someone visits my gallery the script is executed, it takes a look in the picture folder, and then looks for a matching thumbnail in the thumbs folder. If the thumbnail dosn't exist it creates one, if it does exist, the script just shows the thumb in the gallery.

This script also generates the html file so I don't have to go in and add the <img> tag.

Isn't that a little CPU intensive if you put in ( for aguments sake) 60 new pictures. That page would take a long time to load. But That is beside the point... Dir Change -> Script executed... Could be usefull for things other than pics and HTML.

Thanxz for the help,
La`res
_________________
Lares Moreau <lares.moreau@gmail.com>
LRU: 400755 http://counter.li.org
lares/irc.freenode.net
Back to top
View user's profile Send private message
tomk
Bodhisattva
Bodhisattva


Joined: 23 Sep 2003
Posts: 7221
Location: Sat in front of my computer

PostPosted: Sun Dec 14, 2003 1:27 pm    Post subject: Reply with quote

If it's just going to be used for showing images on your website you should look into SSI. You can add scripts which are executed when the page loads. So to see any pictures on my site I've got a litlle bash script that looks at the photo directory and outputs things in HTML so everytime someone looks atr the page it will create a different page depending on what's in the directory. So to add photos all I have to do is put them in the right directory. This works because the only time the script is run is when someone looks at the webpage. If you need to do things to a directory but can't tell when people will access it then using a cron job is probably the best bet.
_________________
Search | Read | Answer | Report | Strip
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum