View previous topic :: View next topic |
Author |
Message |
La`res Arch/Herd Tester
Joined: 11 Aug 2003 Posts: 79 Location: ::0
|
Posted: Fri Dec 12, 2003 9:55 pm Post subject: Monitor a Dir for Changes?? then Run a script...? |
|
|
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. _________________ Lares Moreau <lares.moreau@gmail.com>
LRU: 400755 http://counter.li.org
lares/irc.freenode.net |
|
Back to top |
|
|
slestak Tux's lil' helper
Joined: 13 Jun 2003 Posts: 115
|
Posted: Sat Dec 13, 2003 12:07 am Post subject: |
|
|
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 |
|
|
ogre2112 n00b
Joined: 30 Nov 2003 Posts: 60 Location: East Coast, USA
|
Posted: Sat Dec 13, 2003 2:17 am Post subject: |
|
|
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 |
|
|
nonotme Guru
Joined: 29 Sep 2003 Posts: 356 Location: on.ca
|
Posted: Sat Dec 13, 2003 2:36 am Post subject: |
|
|
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 |
|
|
maddog722 n00b
Joined: 22 Sep 2003 Posts: 24
|
Posted: Sat Dec 13, 2003 4:24 am Post subject: |
|
|
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 |
|
|
nempo Guru
Joined: 16 Apr 2002 Posts: 360 Location: Linkoping, Sweden
|
Posted: Sat Dec 13, 2003 10:39 am Post subject: Re: Monitor a Dir for Changes?? then Run a script...? |
|
|
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. |
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 |
|
|
La`res Arch/Herd Tester
Joined: 11 Aug 2003 Posts: 79 Location: ::0
|
Posted: Sun Dec 14, 2003 10:21 am Post subject: Re: Monitor a Dir for Changes?? then Run a script...? |
|
|
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 |
|
|
tomk Bodhisattva
Joined: 23 Sep 2003 Posts: 7221 Location: Sat in front of my computer
|
Posted: Sun Dec 14, 2003 1:27 pm Post subject: |
|
|
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 |
|
|
|