Skip to content

Instantly share code, notes, and snippets.

@jonatw
Created July 10, 2012 18:06
Show Gist options
  • Save jonatw/3085214 to your computer and use it in GitHub Desktop.
Save jonatw/3085214 to your computer and use it in GitHub Desktop.
sync remote file
#!/bin/bash
src=/tmp/
dest=192.168.1.7
/usr/bin/inotifywait -mrq --format '%w %w%f %e' -e attrib,modify,move,create,delete,close_write $src \
| while read path files event
do
if [ "$event" == "MOVE_TO" ] || [ "$event" == "CREATE" ] || [ "$event" == "ATTRIB" ] || [ "$event" == "CLOSE_WRITE" ]; then
#just scp it
#echo $path
#echo $files $event
ssh root@$dest "mkdir -p $path"
scp -pq $files root@$dest:$path
fi
if [ "$event" == "DELETE" ] ; then
ssh root@$dest "rm $files"
fi
if [ "$event" == "DELETE,ISDIR" ] ; then
ssh root@$dest "rm -rf $files"
fi
if [ "$event" == "CREATE,ISDIR" ] ; then
ssh root@$dest "mkdir -p $files"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment