I am trying to monitor file creation with inotifywait and execute a long script on every file creation. Everything works smoothly when the action to be taken is on the same server. But when it requires doing something on a remote server, the action runs once even 2 files are created in the monitored directory.
This works even if two or more files are created. :
d="path/dir/path/"
inotifywait -m -e create --format '%f' "${d}" | while read FILENAME
do
IFS='-' read -r -a action <<< $FILENAME
if [ ${action[0]} = "dothing" ]
then
rsync -r -v /var/www/site1.com/sub/ /var/www/site2.com/sub/
fi
done
This does not work (involves interaction with another server). It executes once even if 2 or more files are created
d="path/dir/path/"
inotifywait -m -e create --format '%f' "${d}" | while read FILENAME
do
IFS='-' read -r -a action <<< $FILENAME
if [ ${action[0]} = "dothing" ]
then
ssh root@server2ip "rsync -r -v root@server1ip:/var/www/site1.com/sub/ /var/www/site2.com/sub/"
fi
done