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
On Tue, Jan 26, 2010 at 9:20 AM, Alan Hoffmeister alangtk@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.
On Tue, Jan 26, 2010 at 9:31 AM, Alan Hoffmeister alangtk@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/
Greetings,
On Tue, Jan 26, 2010 at 4:50 PM, Alan Hoffmeister alangtk@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
From: Alan Hoffmeister alangtk@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
From: Alan Hoffmeister alangtk@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
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
Em 26/01/2010 10:38, Wade Hampton escreveu:
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 _______________________________________________ CentOS mailing list CentOS@centos.org http://lists.centos.org/mailman/listinfo/centos
I don't know C... I was looking for a bash script...
Alan Hoffmeister wrote:
Em 26/01/2010 10:38, Wade Hampton escreveu:
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
I don't know C... I was looking for a bash script...
If you want to try inotify, rpmforge has inotify-tools rpm. Sample scripts in the man pages.
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.
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...
Alan Hoffmeister wrote:
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...
"Hundreds" is not a big number for rsync - but many thousands might be since it will always transfer the whole directory listing for the comparison. If you have room for another local copy of the files you might rsync locally, then repeat to the remote only if files were transferred. Otherwise you'll at least need to write a script that touches a file to set a current timestamp, then runs find -newer to detect modified files in the tree in question - or hook to inotify which always seemed experimental to me.