Hello everyone! How can I detect if a folder have changed (sync logic) than run a script if it's true? I found this script over the net, but I think it's such complicated for that simple thing... #!/bin/bash ############### detectdir.sh by Jagbir Singh ################# # # script to detect changes in directory. # ############################################################### # directory to watch DIR="/var/www/vhosts" # store current statistics of dir OLD=`stat -t $DIR` while true do # take a new snapshot of stats NEW=`stat -t $DIR` # compare it with old if [ "$NEW" != "$OLD" ]; then echo "changed!" ## you may want to comment this # take current listing of dir in a file. domains may be added or removed. ls $DIR --file-type | grep "\/" | sed 's/\///' > /tmp/dir.list # open file and you can now process entries in it exec 10 let count=0 while read LINE <&10; do # currently printed on screen, can supply this as arg to rSync, discussed later echo $LINE/httpdocs/ echo ((count++)) done # take snapshot again and store it in both old and new vars NEW=`stat -t $DIR` OLD=$NEW exec 10>&- fi # i'm using 3 secs calm time, you should update this as per your environment sleep 3 done -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20100126/c0a69d1c/attachment-0001.html>
On Tue, Jan 26, 2010 at 9:20 AM, Alan Hoffmeister <alangtk at gmail.com> wrote:> Hello everyone! > > How can I detect if a folder have changed (sync logic) than run a script if > it's true? > I found this script over the net, but I think it's such complicated for that > simple thing...IIRC, fam, gamin and some other softwares can do it for you. -- Renato Botelho
Em 26/01/2010 09:28, Renato Botelho escreveu:> > IIRC, fam, gamin and some other softwares can do it for you. > >Could you point me some "how to"? Tanks for the help!
On Tue, Jan 26, 2010 at 9:31 AM, Alan Hoffmeister <alangtk at gmail.com> wrote:> Em 26/01/2010 09:28, Renato Botelho escreveu: >> >> IIRC, fam, gamin and some other softwares can do it for you. >> >> > Could you point me some "how to"?I never played with it, but you can start reading here: http://www.gnome.org/~veillard/gamin/ -- Renato Botelho
Greetings, On Tue, Jan 26, 2010 at 4:50 PM, Alan Hoffmeister <alangtk at gmail.com> wrote:> Hello everyone! > > How can I detect if a folder have changed (sync logic) than run a script if > it's true? >inotify perhaps? never tried that though... regards, Rajagopal -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20100126/98bcfe51/attachment-0001.html>
From: Alan Hoffmeister <alangtk at gmail.com>>How can I detect if a folder have changed (sync logic) than run a >script if it's true? >>I found this script over the net, but I think it's such complicated for >that simple thing...You could do something like (untested): CHECKFILE="/path/to/checkfile" if [! -f $CHECKFILE]; then touch $CHECKFILE; fi find -cnewer $CHECKFILE | myscript.sh touch $CHECKFILE JD
> You could do something like (untested): > > CHECKFILE="/path/to/checkfile" > if [! -f $CHECKFILE]; then touch $CHECKFILE; fi > find -cnewer $CHECKFILE | myscript.sh > touch $CHECKFILE > > JD >I think that now we are on the way, but this script compare the CHECKFILE whit what?
If you know C, you can write a simple program using inotify(7). For example, you could write a program to continually monitor the directory and pass in the script plus args as a arg. See: http://www.ibm.com/developerworks/linux/library/l-inotify.html Cheers, -- Wade Hampton
Alan Hoffmeister wrote:> Hello everyone! > > How can I detect if a folder have changed (sync logic) than run a script > if it's true? > I found this script over the net, but I think it's such complicated for > that simple thing... >You could just run rsync periodically without checking anything. It will only transfer files that have changed and will walk the whole tree doing the comparisons with the -R or -a options. -- Les Mikesell lesmikesell at gmail.com
> You could just run rsync periodically without checking anything. It will only > transfer files that have changed and will walk the whole tree doing the > comparisons with the -R or -a options. > >Yeah i know, but my work is sync lots of small files (hundreds of them), and rsync will stay all day to check all that files on the remote host...
From: Alan Hoffmeister <alangtk at gmail.com>> > You could do something like (untested): > > CHECKFILE="/path/to/checkfile" > > if [! -f $CHECKFILE]; then touch $CHECKFILE; fi > > find -cnewer $CHECKFILE | myscript.sh > > touch $CHECKFILE > I think that now we are on the way, but this script compare the > CHECKFILE whit what?From find man page: -cnewer file File?s status was last changed more recently than file was modified. JD