Detect file change

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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


_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux